File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "read file not include new line" Watch "read file not include new line" New topic
Author

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?
Thanks.
-----------
Code:
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" ){
System.out.println(row+":"+col+">"+Line);
find_col_data(row,Line);
row = row + 1;
}

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

}
--------------------
FileWriter fw = new FileWriter(path + fileName);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
pw.println(sb.toString());
//bw.newLine(); //next line ,counted 1 line
pw.println(input);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: read file not include new line