package com.cnse.iodemo; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; /** * @info標準的字節數組操做工具類 * @author kxw * @see 參考博客__51ct熔岩 * 原則上全部的字節數組操做都是有效的 * 理解爲inputstream 和outputstream 能夠處理的 他的子(類,inter)處理的更快速 從而衍生出多個處理類 */ public class ByteUseDemo { public static void main(String[] args) throws IOException { bytefisUse(); bytefisUse2(); } // 能夠將一張圖片的字節數組編碼放到一個txt文件中 public static void bytefisUse() throws IOException { FileInputStream fis = new FileInputStream("H:\\systemConfig.png");// 某個圖片 FileOutputStream fos = new FileOutputStream("H:\\111.txt");// 講字節數組編碼放到txt文件中 int len = 0; byte[] bt = new byte[512]; while ((len = fis.read(bt)) != -1) { fos.write(bt, 0, len); System.out.println("寫入成功內容爲::___" + new String(bt, "ISO-8859-1")); } fis.close(); fos.close(); } // 從txt文件中讀取字節數組編碼 生成一個png文件 public static void bytefisUse2() throws IOException { FileInputStream fis = new FileInputStream("H:\\111.txt"); FileOutputStream fos = new FileOutputStream("H:\\aaa.png"); int len = 0; byte[] bt = new byte[512]; while ((len = fis.read(bt)) != -1) { fos.write(bt, 0, len); System.out.println("寫入成功內容爲::___" + new String(bt, "ISO-8859-1")); } fis.close(); fos.close(); } }