-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCopy.java
More file actions
executable file
·60 lines (58 loc) · 1.86 KB
/
Copy.java
File metadata and controls
executable file
·60 lines (58 loc) · 1.86 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
58
59
60
/* */ package ch17;
/* */
/* */ import java.io.BufferedInputStream;
/* */ import java.io.BufferedOutputStream;
/* */ import java.io.File;
/* */ import java.io.FileInputStream;
/* */ import java.io.FileOutputStream;
/* */ import java.io.IOException;
/* */
/* */ public class Copy {
/* */ public static void main(String[] args) throws IOException {
/* 12 */ if (args.length != 2) {
/* 13 */ System.out.println("Usage: java Copy sourceFile targetfile");
/* */
/* 15 */ System.exit(1);
/* */ }
/* */
/* */
/* 19 */ File sourceFile = new File(args[0]);
/* 20 */ if (!sourceFile.exists()) {
/* 21 */ System.out.println("Source file " + args[0] + " does not exist");
/* */
/* 23 */ System.exit(2);
/* */ }
/* */
/* */
/* 27 */ File targetFile = new File(args[1]);
/* 28 */ if (targetFile.exists()) {
/* 29 */ System.out.println("Target file " + args[1] + " already exists");
/* */
/* 31 */ System.exit(3);
/* */ }
/* */
/* */
/* */
/* 36 */ try(BufferedInputStream input = new BufferedInputStream(new FileInputStream(sourceFile));
/* */
/* */
/* */
/* 40 */ BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(targetFile))) {
/* */
/* */
/* */
/* 44 */ int numberOfBytesCopied = 0; int r;
/* 45 */ while ((r = input.read()) != -1) {
/* 46 */ output.write((byte)r);
/* 47 */ numberOfBytesCopied++;
/* */ }
/* */
/* */
/* 51 */ System.out.println(numberOfBytesCopied + " bytes copied");
/* */ }
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch17/Copy.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/