-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCopy.java
More file actions
25 lines (24 loc) · 818 Bytes
/
Copy pathCopy.java
File metadata and controls
25 lines (24 loc) · 818 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
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Copy{
public static void main(String[] args) {
if(args.length != 2){
System.err.println("usage: java Copy srcFile srcFile");
return;
}
// ARM, Java added automatic resource management feature implementation in below form.
try(FileInputStream fis = new FileInputStream(args[0]);
FileOutputStream fos = new FileOutputStream(args[1])){
// resource usage block, you can follow it with catch and/or finally block.
int b;
while((b=fis.read())!=-1){
fos.write(b);
}
}catch(IOException ioe){
ioe.printStackTrace();
};
// No resource release tedious handle any more:)
}
}