package io_for_pic;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class FileIo {
//读取
C:/001.jpg
图片转换为字节byte[]数组
public byte[] inp() throws Exception{
File f = new File("C:/001.jpg");
InputStream is = new FileInputStream(f);
byte[] bt = new byte[(int)f.length()];
is.read(bt);
is.close();
System.out.println(bt);
return bt;
}
//根据字节byte[]数组转换为图片002.jpg保存在C盘下
public void op(byte[] bt) throws Exception{
OutputStream os = new FileOutputStream(new File("c:/002.jpg"));
os.write(bt);
os.flush();
os.close();
}
public static void main(String[] args) throws Exception{
FileIo ips = new FileIo();
ips.op(ips.inp());
}
}