-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileCopyBytes.java
More file actions
54 lines (44 loc) · 1.55 KB
/
FileCopyBytes.java
File metadata and controls
54 lines (44 loc) · 1.55 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
package Fach_6_FileIO;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileCopyBytes {
public static void main(String[] args) {
// dieses klasse zeigt nur das kopieren-konzept auf, mittels BINARY COPY
// wenn man CHARACTER COPY machen moechte, dann muesste man
// den FileReader/FileWriter anstatt FileInputStream/FileOutputStream
// zudem git es die Files.copy Methode, ist viel einfacher, siehe FileCopyFiles.java!
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream("src/main/java/Fach_6_FileIO/myDirectory/songs.txt");
out = new FileOutputStream("src/main/java/Fach_6_FileIO/myDirectory/songs-copy.txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
// schliessen
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (out != null) {
try {
// schliessen
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}