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();
}
}
转载于:https://my.oschina.net/u/2425851/blog/617227