Java IO--字節流復制圖片實例。本站提示廣大學習愛好者:(Java IO--字節流復制圖片實例)文章只能為提供參考,不一定能成為您想要的結果。以下是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 }