把字符串字節數組寫入文件


 /** * Java,把字符串字節數組寫入文件 * @param byt * @throws Exception */
    private static void byte2File(byte[] byt) throws Exception { if (null == byt) { return; } String targetFile = "C:\\Users\\fileTestTarget.txt"; File file = new File(targetFile); OutputStream output = new FileOutputStream(file); BufferedOutputStream out = new BufferedOutputStream(output); InputStream in = new ByteArrayInputStream(byt); byte[] buff = new byte[1024]; int len = 0; while ((len = in.read(buff)) != -1) { out.write(buff, 0, len); } in.close(); out.close(); System.out.println("---- done ----"); }

       如果入參是字符串“HelloWorld”的字節數組,則可以吧HellowWorld寫入fileTestTarget.txt。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM