This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes read file not include new line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "read file not include new line" Watch "read file not include new line" New topic

read file not include new line

Sophia Choi
Ranch Hand

Joined: Mar 22, 2002
Posts: 106
I have tried to write data into a file.So, I read the file first using Buffered Reader and save them into a 2D array. Then, I use PrintWriter and write them into a file. In order to have a good looking, I use println.
But, when I read that file again, the newline is included and counted to be a line. How can I ignore it?
FileReader fr = new FileReader(path + fileName);
BufferedReader br = new BufferedReader(fr);
String Line = br.readLine();
while(Line != null )
//System.out.println(Line + "<BR>"); //output
if(row == 0) find_col_num(Line);
sb = sb.append( Line);
sb = sb.append("\n"); //new line for screen
if(row < max_rows || Line != "\n" ){
row = row + 1;

Line = br.readLine(); //read next

FileWriter fw = new FileWriter(path + fileName);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
//bw.newLine(); //next line ,counted 1 line
Have you tried LearnNowOnline?
subject: read file not include new line