I am trying to copy the contents of one text file ("1.txt") which contains 2-3 integer numbers (ex: 1 2 3) to another text file ("2.txt") but I am getting the following error upon compilation
import java.io.*;
class FileDemo {
public static void main(String args[]) {
try {
FileReader fr=new FileReader("1.txt");
FileWriter fw=new FileWriter("2.txt");
int c=fr.read();
while(c!=-1) {
fw.write(c);
}
} catch(IOException e) {
System.out.println(e);
} finally() {
fr.close();
fw.close();
}
}
}
Command prompt:-
C:\Documents and Settings\Salman\Desktop>javac FileDemo.java
FileDemo.java:20: error: '{' expected
finally()
^
FileDemo.java:20: error: illegal start of expression
finally()
^
FileDemo.java:20: error: ';' expected
finally()
^
FileDemo.java:27: error: reached end of file while parsing
}
^
4 errors
But upon checking the code, I find that the finally() block is properly closed.