-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyFile.java
More file actions
34 lines (30 loc) · 1.01 KB
/
CopyFile.java
File metadata and controls
34 lines (30 loc) · 1.01 KB
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
import java.io.*;
class CopyFile {
public static void main(String args[]) {
int i;
if(args.length != 2) {
System.out.println("Usage: CopyFile <start_file> <target_file>");
return;
}
try (FileInputStream fin = new FileInputStream(args[0]);
FileOutputStream fout = new FileOutputStream(args[1])) {
do {
i = fin.read();
if(i != -1) fout.write(i);
} while(i != -1);
} catch(IOException exc) {
System.out.println("Input/Output error: " + exc);
} /*finally {
try {
if(fin != null) fin.close();
} catch(IOException exc) {
System.out.println("Closing error for input file");
}
try {
if(fout != null) fout.close();
} catch(IOException exc) {
System.out.println("Closing error for output file");
}
}*/
}
}