print new line in files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • analoveu
    New Member
    • Jan 2007
    • 36

    print new line in files

    how can I print new line in a file using a reference to Formatter object

    Code:
    //create reference to file to read from
    Scanner input=new Scanner(new File("d:\\records1.txt"));
    
    //create reference to file to write
    Formatter output=new Formatter("d:\\records7.txt");
    
    while(input.hasNext()){
      
               output.format(input.nextLine());
               output.format();
    }
    what should I print in output.format() to promote the file to inter new line before printing the next line that it reads from input
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by analoveu
    how can I print new line in a file using a reference to Formatter object

    Code:
    //create reference to file to read from
    Scanner input=new Scanner(new File("d:\\records1.txt"));
    
    //create reference to file to write
    Formatter output=new Formatter("d:\\records7.txt");
    
    while(input.hasNext()){
      
               output.format(input.nextLine());
               output.format();
    }
    what should I print in output.format() to promote the file to inter new line before printing the next line that it reads from input
    You could do that a few different ways, either output.newLine( ); or use '\n' the newline character.

    Comment

    • analoveu
      New Member
      • Jan 2007
      • 36

      #3
      Originally posted by sicarie
      You could do that a few different ways, either output.newLine( ); or use '\n' the newline character.
      no that is not allowed class Formatter dont include method newLine
      so I can't use newLine() on Formatter object
      an also when I wite
      output.format("/n") it print /n in the file
      if I print output.format(/n) also there is error

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by analoveu
        no that is not allowed class Formatter dont include method newLine
        so I can't use newLine() on Formatter object
        an also when I wite
        output.format("/n") it print /n in the file
        if I print output.format(/n) also there is error
        Your slash is pointed the wrong direction. Try "\n".

        Comment

        • lucky001
          New Member
          • Mar 2007
          • 4

          #5
          you are suppose to write "\n" instead of writing "/n" or /n

          e.g.

          output.format(" \n");


          I hope this will work

          Comment

          Working...