- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyFile2.java
More file actions
Latest commit
31 lines (26 loc) · 959 Bytes
/
Copy pathCopyFile2.java
File metadata and controls
31 lines (26 loc) · 959 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
// implement the C-lang binary 'cp' in Java
// (slightly different version, based on the documentation from Oracle)
importjava.io.FileInputStream;
importjava.io.FileOutputStream;
importjava.io.FileNotFoundException;
importjava.io.IOException;
classCopyFile2 {
publicstaticvoidmain(String[] args) {
if (args.length != 2) {
System.out.println("Wrong number of arguments.");
System.out.println("Usage: CopyFile <file_in> <file_out>");
return;
}
// character placeholder
intc;
try(FileInputStreamaFileIn = newFileInputStream(args[0]);
FileOutputStreamaFileOut = newFileOutputStream(args[1])) {
// not 'do...while'!
while ((c = aFileIn.read()) != -1)
aFileOut.write(c);
} catch (IOExceptionaExc) {
System.out.println("I/O Error: " + aExc);
aExc.printStackTrace();
}
}
}