1 // CopyFile.java
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.io.OutputStream;
6 import java.nio.file.Files;
7 import java.nio.file.Paths;
8
9 /** 10 * CopyFile zeigt den Umgang mit File-Streams. 11 * @author H.Drachenfels 12 * @version 10.1.2019 13 */
14 public final class CopyFile {
15 private CopyFile() { }
16
17 /** 18 * Kopiert eine Datei. 19 * @param args Quell- und Zieldateinamen 20 * @throws IOException bei Dateizugriffsfehlern 21 */
22 public static void main(String[] args) throws IOException {
23 try (
24 InputStream in = Files.newInputStream(Paths.get(args[0]));
25 OutputStream out = Files.newOutputStream(Paths.get(args[1]));
26 ) {
27 int b;
28 while ((b = in.read()) != -1) {
29 out.write(b);
30 }
31 } // automatische Aufrufe in.close() und out.close()
32 }
33 }
34