forked from TimSongCoder/LearnJavaForAndroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyCopy.txt
More file actions
42 lines (41 loc) · 864 Bytes
/
Copy pathCopyCopy.txt
File metadata and controls
42 lines (41 loc) · 864 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
36
37
38
39
40
41
42
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class Copy{
public static void main(String[] args){
if(args.length != 2){
System.err.println("usage: java Copy srcfile dstfile");
return;
}
FileInputStream fis = null;
FileOutputStream fos = null;
try{
fis = new FileInputStream(args[0]);
fos = new FileOutputStream(args[1]);
int b;
while((b=fis.read())!=-1){
fos.write(b);
}
}catch(FileNotFoundException fnfe){
fnfe.printStackTrace();
}catch(IOException ioe){
ioe.printStackTrace();
}finally{
if(fis!=null){
try{
fis.close();
}catch(IOException ioe){
ioe.printStackTrace();
}
}
if(fos!=null){
try{
fos.close();
}catch(IOException ioe){
ioe.printStackTrace();
}
}
}
}
}