Java IO--字节流复制图片实例

字节流用来操作图片、视屏、音频(进制文件)

 1 package learn;
 2 
 3 import java.io.*;
 4 
 5 public class Learn{
 6     public static void main(String[] args) throws IOException {
 7         File file1=new File("D:/a.jpg");
 8         File file2=new File("D:/b.jpg");
 9         byte[] b=new byte[(int)file1.length()];
10         FileInputStream in=null;
11         FileOutputStream out=null;
12         try {
13             in=new FileInputStream(file1);
14             out=new FileOutputStream(file2);//没有指定文件则会创建
15             while(in.read(b)!=-1){        //read()--int,-1表示读取完毕
16                 out.write(b);
17             }
18             out.flush();
19             in.close();
20             out.close();
21         } catch (FileNotFoundException e) {
22             e.printStackTrace();
23         }
24     }
25 }

 

posted @ 2017-02-07 20:05  LookOutTheBush  阅读(757)  评论(0编辑  收藏  举报