• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Write a new Line

 
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i wrote a bello file.but it writ all things into one line.how to remove it.

public static void main(String [] args) {

try{
File file =new File("F:\\name.txt");
FileReader fr =new FileReader(file);
BufferedReader br =new BufferedReader(fr);
File file2 = new File("E:\\ana\\write.txt");
FileWriter fw =new FileWriter(file2);

String size = br.readLine();

while(!(size==null))
{
System.out.println("br.readLine(); "+size);

fw.write(size);
fw.write("\\n");
size=br.readLine();
}

fw.flush();
fr.close();
}catch(IOException e)
{
e.printStackTrace();
}
}
}
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this related to EJB or is it a Java-General-beginner question??
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
" fw.write("\\n") " should read fw.write("\n") ", otherwise you're printing a backslash and an "n".

But using "\n" for newline is platform-specific for Unix/Linux; is that what you're using? For Windows, it'd be "\r\n". Or you could use a BufferedWriter that has a "newLine" method.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic