summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/FileCopy.java
blob: deb3309393fe51be8d4cb99599d3ecdc26461922 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* FileCopy.java */

import java.io.*;

public class FileCopy
{
  public static void main(String[] args)
  {
    if (args.length != 2) {
      System.out.println("java FileCopy inputfile outputfile");
      System.exit(1);
    }
    try {
      FileInputStream in = new FileInputStream(args[0]);
      FileOutputStream out = new FileOutputStream(args[1]);
      byte[] buf = new byte[4096];
      int len;
      while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
      }
      out.close();
      in.close();
    } catch (IOException e) {
      System.err.println(e.toString());
    }
  }
}