Newer
Older
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.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileCopy {
// geprüfte exceptions
public static void main(String[] args) throws FileNotFoundException, IOException {
FileInputStream fis = null;
FileOutputStream fos = null;
// Exception-Handler für ungeprüfte exceptions
try {
fis = new FileInputStream(args[0]);
fos = new FileOutputStream(args[1]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Die Parameterliste beim Programmaufruf sollte sein:");
System.out.println("java FileCopy quelldatei zieldatei");
return;
} catch (Exception e) {
if ( !"0".equals(e.getMessage()) ) {
System.out.println(e.getMessage());
}else {
System.out.println("Ein unerwarteter Fehler trat auf!");
}
return;
}
int c;
c = fis.read();
while ( c != -1 ) {
fos.write(c);
c = fis.read();
}
fis.close();
fos.close();
}
}