-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ6(Practical).java
More file actions
37 lines (33 loc) · 804 Bytes
/
Q6(Practical).java
File metadata and controls
37 lines (33 loc) · 804 Bytes
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
6.Write a program that copies content of one file to another. Pass the names of the files through command-line arguments.
/**** Copy.java ****/
import java.io.*;
public class Copy {
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.err.println("Usage: java Copy <src> <dest>");
} else {
int i;
FileInputStream fin = new FileInputStream(args[0]);
FileOutputStream fout = new FileOutputStream(args[1]);
while ((i = fin.read()) != -1) {
fout.write(i);
}
fin.close();
fout.close();
System.out.println(
"Copied contents of" + args[0] + " to " + args[1]
);
}
}
}
Output -
> java Copy src.txt dest.txt
Copied contents of src.txt to dest.txt
> type .\src.txt
Harsh Meena
===========
University of Delhi
> type .\dest.txt
Harsh Meena
===========
University of Delhi