aspose file tools*
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 Spring in Action this week in the Spring 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 liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1204
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: 9305
    
  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: 10210
    
166

Moving.

[My Blog] [JavaRanch Journal]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
" 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