-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCopy.java
More file actions
48 lines (47 loc) · 1.06 KB
/
Copy pathCopy.java
File metadata and controls
48 lines (47 loc) · 1.06 KB
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
43
44
45
46
47
48
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
public class Copy{
public static void main(String[] args){
if(args.length != 2){
System.err.println("usage: java Copy srcfile dstfile");
return;
}
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
FileInputStream fis = null;
FileOutputStream fos = null;
try{
fis = new FileInputStream(args[0]);
bis = new BufferedInputStream(fis);
fos = new FileOutputStream(args[1]);
bos = new BufferedOutputStream(fos);
int b;
while((b=bis.read())!=-1){
bos.write(b);
}
}catch(FileNotFoundException fnfe){
fnfe.printStackTrace();
}catch(IOException ioe){
ioe.printStackTrace();
}finally{
if(bis!=null){
try{
bis.close();
}catch(IOException ioe){
ioe.printStackTrace();
}
}
if(bos!=null){
try{
bos.close();
}catch(IOException ioe){
ioe.printStackTrace();
}
}
}
}
}