Java IO--字节流复制图片实例
字节流用来操作图片、视屏、音频(进制文件)
实例代码:
package learn; import java.io.*; public class Learn{ public static void main(String[] args) throws IOException { File file1=new File("D:/a.jpg"); File file2=new File("D:/b.jpg"); byte[] b=new byte[(int)file1.length()]; FileInputStream in=null; FileOutputStream out=null; try { in=new FileInputStream(file1); out=new FileOutputStream(file2);//没有指定文件则会创建 while(in.read(b)!=-1){ //read()--int,-1表示读取完毕 out.write(b); } out.flush(); in.close(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!