1 parent b3171a0 commit d7f9137Copy full SHA for d7f9137
3 files changed
Chapter16/Copy.java
@@ -0,0 +1,25 @@
1
+import java.io.FileInputStream;
2
+import java.io.FileOutputStream;
3
+import java.io.FileNotFoundException;
4
+import java.io.IOException;
5
+
6
+public class Copy{
7
+ public static void main(String[] args) {
8
+ if(args.length != 2){
9
+ System.err.println("usage: java Copy srcFile srcFile");
10
+ return;
11
+ }
12
+ // ARM, Java added automatic resource management feature implementation in below form.
13
+ try(FileInputStream fis = new FileInputStream(args[0]);
14
+ FileOutputStream fos = new FileOutputStream(args[1])){
15
+ // resource usage block, you can follow it with catch and/or finally block.
16
+ int b;
17
+ while((b=fis.read())!=-1){
18
+ fos.write(b);
19
20
+ }catch(IOException ioe){
21
+ ioe.printStackTrace();
22
+ };
23
+ // No resource release tedious handle any more:)
24
25
+}
Chapter16/CopyResult.png
27.9 KB
Chapter16/MulticatchStatement.png
0 commit comments