The Java Program: 5-exceptional-puzzlers/puzzle-41/Copy.java
1 import java.io.*;
2
3 public class Copy {
4 static void copy(String src, String dest) throws IOException {
5 InputStream in = null;
6 OutputStream out = null;
7 try {
8 in = new FileInputStream(src);
9 out = new FileOutputStream(dest);
10 byte[] buf = new byte[1024];
11 int n;
12 while ((n = in.read(buf)) > 0)
13 out.write(buf, 0, n);
14 } finally {
15 if (in != null) in.close();
16 if (out != null) out.close();
17 }
18 }
19
20 public static void main(String[] args) throws IOException {
21 if (args.length != 2)
22 System.out.println("Usage: java Copy <source> <dest>");
23 else
24 copy(args[0], args[1]);
25 }
26 }