// LineReturnFixer1.java
//
// Copies one text file to another.
// The original file is read in a platform-independent fashion.
// In the copy, end-of-line markers will be appropriate to the
// platform on which the program is run.  The copy will have
// the same name as the original file plus the prefix "fixed-".
//
// Illustrates use of java.io class PrintWriter for text file
// output and java.io class BufferedReader for both text file
// input and prompted command-line input.
//
// IOExceptions are re-thrown.

import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.PrintWriter;

public class LineReturnFixer1  {
   public static void main(String[] args) throws IOException
   {
      BufferedReader keyboardIn = new BufferedReader(
                                      new InputStreamReader(System.in),
                                      1);

      System.out.print("Enter name of file to be fixed: ");
      String inputFileName = keyboardIn.readLine();
      String outputFileName = "fixed-" + inputFileName;

      // Open files for reading and writing:
      BufferedReader br = new BufferedReader(
                             new InputStreamReader(
                                new FileInputStream(inputFileName)));
      PrintWriter pw = new PrintWriter(
                          new BufferedWriter(
                              new OutputStreamWriter(
                                 new FileOutputStream(outputFileName))));

      // Copy one file to the other, until end-of-file:
      while (true)
      {
         String line = br.readLine();
         if ( line == null )
            break;
         pw.println(line); 
      }  // while


      // Send output from buffer to the file itself:
      pw.flush();

      // Close files and buffers:
      br.close();
      pw.close();

      // Inform user that the job has been completed:
      System.out.println("File " + outputFileName + " has been created.");
   }  // method main(String[])
}  // class LineReturnFixer1