1 import java.io.FileInputStream;
2 import java.io.FileNotFoundException;
3 import java.io.FileOutputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
6
7 public class Test {
8
9 public static void main(String[] args) {
10 // 将一个文件复制到另一个地方
11 // 先读入再读出
12 // 取货员和送货员一起工作
13 // 加大作用域
14 InputStream input = null;
15 FileOutputStream output = null;
16 try {
17 input = new FileInputStream("java.txt");//
18 output = new FileOutputStream("javacopy.txt");
19 // 找一个筐筐
20
21 byte[] ch = new byte[1024];
22 // 把要的东西一个个放到筐筐里
23 int length = 0;
24 // 取货员把东西搬到一个筐筐里 就走两步把筐里的东西一个个拿给送货员
25 while ((length = input.read(ch)) != -1) {
26 output.write(ch);
27
28 }
29 } catch (FileNotFoundException e) {
30 e.printStackTrace();
31 } catch (IOException e) {
32 e.printStackTrace();
33 } finally {
34 try {
35 output.close();
36 } catch (IOException e) {
37 e.printStackTrace();
38 }
39 try {
40 input.close();
41 } catch (IOException e) {
42 e.printStackTrace();
43 }
44 }
45
46 }
47
48 }