This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Write a new Line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Write a new Line" Watch "Write a new Line" New topic
Author

Write a new Line

sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1072
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

Joined: Aug 03, 2008
Posts: 9291
    
  17

Is this related to EJB or is it a Java-General-beginner question??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9947
    
161

Moving.

[My Blog] [JavaRanch Journal]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41129
    
  45
" 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.


Ping & DNS - my free Android networking tools app
 
 
subject: Write a new Line
 
Similar Threads
Why no output is given here
File not found exception
Writing to File
FileReader and FileWriter
Create .txt file