-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileCopy.java
More file actions
30 lines (22 loc) · 779 Bytes
/
FileCopy.java
File metadata and controls
30 lines (22 loc) · 779 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
import java.io.*;
public class FileCopy {
public static void main(String[] args) {
try {
// Source file
FileInputStream fin = new FileInputStream("input.txt");
// Destination file
FileOutputStream fout = new FileOutputStream("output.txt");
int ch;
// Read and write byte by byte
while((ch = fin.read()) != -1) {
fout.write(ch);
}
System.out.println("File copied successfully!");
// Close files
fin.close();
fout.close();
} catch(IOException e) {
System.out.println("Error: " + e);
}
}
}