title: Converting a .java file to a .txt document
body: <p>I am trying to figure out how to load a .java doc and out put it into a text document... </p>
  
  <p>What needs to be done: </p>
  
  <blockquote>
    <p>Write a program that opens a Java source file, adds line numbers, and
    saves the result in a new file. Line numbers are numbers which
    indicate the different lines of a source file, they are useful when
    trying to draw someone's attention to a particular line (e.g.,
    "there's a bug on line 4"). Your program should prompt the user to
    enter a filename, open it, and then save each line to an output fix
    with the line numbers prepended to the beginning of each line.
    Afterward, display the name of the output file. The name of the output
    file should based on the input file with the '.' replaced by a '_',
    and ".txt" added to the end. (Hint: if you are using a PrintWriter
    object called pw to save the text file, then the line
    "pw.printf("%03d", x);" will display an integer x padded to three
    digits with leading zeros.)</p>
  </blockquote>
  
  <p>The text.java needs to output into the text document with numbered lines such as:</p>
  
  <p>001 public class dogHouse {</p>
  
  <p>002 public static void main (String[] args) { </p>
  
  <p>003 and so on...</p>
  
  <p>004</p>
  
  <pre><code>import java.io.*;
  
      public class dogHouse {
          public static void main(String [] args) throws IOException {
  
              // The name of the file to open.
              String fileName = "test.java";
  
              // This will reference one line at a time
              String line = null;
  
              try {
                  // FileReader reads text files in the default encoding.
                  FileReader fileReader = 
                      new FileReader(fileName);
  
                  // Always wrap FileReader in BufferedReader.
                  BufferedReader bufferedReader = 
                      new BufferedReader(fileReader);
  
                  while((line = bufferedReader.readLine()) != null) {
                      System.out.println(line);
                  }   
  
                  // Always close files.
                  bufferedReader.close();         
              }
  
              // The name of the file to open.
              finally {
                  // Assume default encoding.
                  FileWriter fileWriter =
                      new FileWriter(fileName);
  
                  // Always wrap FileWriter in BufferedWriter.
                  BufferedWriter bufferedWriter =
                      new BufferedWriter(fileWriter);
  
                  // Note that write() does not automatically
                  // append a newline character.
                  bufferedWriter.write("Hello there,");
                  // Always close files.
                  bufferedWriter.close();
              }
          }
      }
  </code></pre>