forked from yfain/Java4Kids_code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileCopy.java
More file actions
35 lines (27 loc) · 921 Bytes
/
Copy pathFileCopy.java
File metadata and controls
35 lines (27 loc) · 921 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
package niosamples;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* Created by NewProgrammer on 3/28/15.
*/
public class FileCopy {
public static void main(String[] args) {
if (args.length != 2) {
System.out.println(
"Please provide source and destination file names, for example:");
System.out.println("java FIleCopy abc.dat copyOfabc.dat");
// Exit the program
System.exit(0);
}
Path sourcePath = Paths.get(args[0]);
Path destinationPath = Paths.get(args[1]);
try {
Files.copy(sourcePath, destinationPath);
System.out.println("The file " + args[0] + " is copied to " + args[1]);
} catch (IOException ioe) {
System.out.println("Can't copy file: " + ioe.getMessage());
}
}
}