title: Copying the Contents of One text file to Another in Java
body: <p>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</p>
  
  <pre><code>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();
        }
      }
  }
  </code></pre>
  
  <p>Command prompt:-</p>
  
  <pre><code>C:\Documents and Settings\Salman\Desktop&gt;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
  </code></pre>
  
  <p>But upon checking the code, I find that the finally() block is properly closed.</p>