title: Reading/Writing Files in Java and Adding Line Numbers
body: <p>I have the following assignment to complete:</p>
  
  <p>Wrote a program that reads a file and writes a copy of the file to another file with line numbers inserted.</p>
  
  <p>So far, I wrote the code that is posted below. This code reads and copies the text to another file, but I cannot figure out how to number each line in the new text file. Can someone please advise me on how to do so?</p>
  
  <pre><code>import java.io.*;
  
  class FileCopy
  {
     public static void main(String[] args) 
     {
        try 
        {
           File fileIn  = new File("Assign4.txt");
           File fileOut = new File("target.txt");
  
           FileInputStream streamIn   = new FileInputStream(fileIn);
           FileOutputStream streamOut = new FileOutputStream(fileOut);
  
           int c;
           while ((c = streamIn.read()) != -1) 
           {
              streamOut.write(c);
           }
  
           streamIn.close();
           streamOut.close();
        }
        catch (FileNotFoundException e) 
        {
           System.err.println("FileCopy: " + e);
        } 
        catch (IOException e) 
        {
           System.err.println("FileCopy: " + e);
        }
     }
  }
  </code></pre>
  
  <p>Thank you, I appreciate your help.</p>