Java IO中字节流复制图片实现代码
JavaIO--字节流复制图片实例
字节流用来操作图片、视屏、音频(进制文件)
实例代码:
packagelearn;
importjava.io.*;
publicclassLearn{
publicstaticvoidmain(String[]args)throwsIOException{
Filefile1=newFile("D:/a.jpg");
Filefile2=newFile("D:/b.jpg");
byte[]b=newbyte[(int)file1.length()];
FileInputStreamin=null;
FileOutputStreamout=null;
try{
in=newFileInputStream(file1);
out=newFileOutputStream(file2);//没有指定文件则会创建
while(in.read(b)!=-1){//read()--int,-1表示读取完毕
out.write(b);
}
out.flush();
in.close();
out.close();
}catch(FileNotFoundExceptione){
e.printStackTrace();
}
}
}
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!