forked from Apress/learn-java-for-android-dev-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopy.java
More file actions
57 lines (55 loc) · 1.43 KB
/
Copy pathCopy.java
File metadata and controls
57 lines (55 loc) · 1.43 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
49
50
51
52
53
54
55
56
57
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
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; // I chose b instead of byte because byte is a reserved word.
while ((b = fis.read()) != -1)
fos.write(b);
}
catch (FileNotFoundException fnfe)
{
System.err.println(args[0] + " could not be opened for input, or " +
args[1] + " could not be created for output");
}
catch (IOException ioe)
{
System.err.println("I/O error: " + ioe.getMessage());
}
finally
{
if (fis != null)
try
{
fis.close();
}
catch (IOException ioe)
{
assert false; // shouldn't happen in this context
}
if (fos != null)
try
{
fos.close();
}
catch (IOException ioe)
{
assert false; // shouldn't happen in this context
}
}
}
}