2 Replies Latest reply: Jan 10, 2009 7:28 PM by 807589 RSS

    java filewriter to text file.  Little box return symbols.

    807589
      I have to use fileWriter for an output file. I also need the text file to do real returns instead of those return box symbols (sorry, I don't know what they are called).

      This is the code I have:
      import java.io.FileReader;
      import java.io.FileWriter;
      import java.io.IOException;
      import java.util.Scanner;
      
      public class FileInput{
           
           public void copyCharacters()
           {
                try{     
                     
                     FileReader fr = new FileReader("widgets.txt");
                     FileWriter fw = new FileWriter("test.txt");
                     Scanner in = new Scanner(fr);
                
                     while(  in.hasNext()  ){      
                          String text = in.nextLine(); 
                          //fw.println(text);  //<-----will not compile
                                      fw.write(text + "\n"); //makes return squares instead of real return
                     }
                
                     in.close();
                     fw.close();
                } 
                catch(IOException e){
                System.out.println("error opening file" + e);
                }
           }
           
           public static void main (String[]args)
           {
                FileInput reader = new FileInput();
                reader.copyCharacters();
           }
      }