Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

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: 9686
42
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: 43026
76
  • 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.
 
Quick! Before anybody notices! Cover it up with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic