1 import java.io.*;
2
3 public class TestFileOutputStream {
4 public static void main(String[] args){
5 int b=0;
6 FileInputStream in=null;
7 FileOutputStream out=null;
8
9 try{
10 in=new FileInputStream("c:/windows/notepad.exe");
11 out=new FileOutputStream("c:/notepad.exe");
12 while((b=in.read())!=-1){out.write(b);}
13 in.close();
14 out.close();
15
16 } catch (FileNotFoundException e2){
17 System.out.println("找不到指定文件");System.exit(-1);
18 } catch (IOException e1){
19 System.out.println("文件復制錯誤");System.exit(-1);
20 }
21
22 System.out.println("文件已復制");
23 }
24 }
25
2
3 public class TestFileOutputStream {
4 public static void main(String[] args){
5 int b=0;
6 FileInputStream in=null;
7 FileOutputStream out=null;
8
9 try{
10 in=new FileInputStream("c:/windows/notepad.exe");
11 out=new FileOutputStream("c:/notepad.exe");
12 while((b=in.read())!=-1){out.write(b);}
13 in.close();
14 out.close();
15
16 } catch (FileNotFoundException e2){
17 System.out.println("找不到指定文件");System.exit(-1);
18 } catch (IOException e1){
19 System.out.println("文件復制錯誤");System.exit(-1);
20 }
21
22 System.out.println("文件已復制");
23 }
24 }
25