forked from jbloch/effective-java-3e-source-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopy.java
More file actions
24 lines (20 loc) · 732 Bytes
/
Copy pathCopy.java
File metadata and controls
24 lines (20 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package effectivejava.chapter2.item9.trywithresources;
import java.io.*;
public class Copy {
private static final int BUFFER_SIZE = 8 * 1024;
// try-with-resources on multiple resources - short and sweet (Page 35)
static void copy(String src, String dst) throws IOException {
try (InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst)) {
byte[] buf = new byte[BUFFER_SIZE];
int n;
while ((n = in.read(buf)) >= 0)
out.write(buf, 0, n);
}
}
public static void main(String[] args) throws IOException {
String src = args[0];
String dst = args[1];
copy(src, dst);
}
}