title: Java IO: Using scanner and printWriter to copy the contents of a text file and put them in another text file
body: <p>Alright so I have a very small program I'm working on designed to take the contents of a text file, test.txt, and put them in another empty file testCopied.txt . The trick is that I want to use Scanner and printWriter as I am trying to understand these a bit better. </p>
  
  <p>Here is what my code looks like:</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class CopyA
  {
     public static void main(String [] args)
     {
        String Input_filename = args[0];
        String Output_filename = args[1];
        char r = args[2].charAt(0);
  
        try
        {
           Scanner sc = new Scanner(new File(Input_filename));
           FileWriter fw = new FileWriter(Output_filename);
           PrintWriter printer = new PrintWriter(fw);
  
           while(sc.hasNextLine())
           {
              String s = sc.nextLine();
              printer.write(s);
           }
           sc.close();               
        }
        catch(IOException ioe)
        {
           System.out.println(ioe);
        }
     }
  }
  </code></pre>
  
  <p>This compiles, but when I look at testCopied.txt it is still blank, and hasn't had test.txt's content transferred to it. What am I doing wrong? Java IO is pretty confusing to me, so I'm trying to get a better grasp on it. Any help is really appreciated!</p>