-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution2.java
More file actions
36 lines (33 loc) · 768 Bytes
/
Copy pathSolution2.java
File metadata and controls
36 lines (33 loc) · 768 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
25
26
27
28
29
30
31
32
33
34
35
36
package Puzzle41;
import java.io.Closeable;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class Solution2 {
static void copy(String src, String dest) throws IOException {
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(src);
out = new FileOutputStream(dest);
byte[] buf = new byte[1024];
int n;
while((n = in.read(buf)) >= 0)
out.write(buf, 0, n);
} finally {
closeIgnoringException(in);
closeIgnoringException(out);
}
}
private static void closeIgnoringException (Closeable c) {
if (c != null){
try{
c.close();
} catch(IOException e){
// do something...
}
}
}
}