1import java.io.*;
2public class CopyFile {
3
4 public static void main(String args[]) throws IOException {
5 FileInputStream in = null;
6 FileOutputStream out = null;
7
8 try {
9 in = new FileInputStream("input.txt");
10 out = new FileOutputStream("output.txt");
11
12 int c;
13 while ((c = in.read()) != -1) {
14 out.write(c);
15 }
16 }finally {
17 if (in != null) {
18 in.close();
19 }
20 if (out != null) {
21 out.close();
22 }
23 }
24 }
25}
1import java.io.File; // Import the File class
2
3File myObj = new File("filename.txt"); // Specify the filename
4