把字符串字节数组写入文件


 /** * 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