File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Write a new Line

 
sam liya
Ranch Hand
Posts: 1240
  • 0
  • Mark post as helpful
  • send pies
  • 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();
}
}
}
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this related to EJB or is it a Java-General-beginner question??
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic