• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Zero length lines when reading a file

I have a JAVA (1.2) program which reads in a file, and after modifying it writes it back out to the same file name. When I run the program a second time I get a zero length record after each line. However if I open the file with an editor, modify it (e.g. add and remove a space) and then save it my program doesn't find any zero length lines. I am using:
         BufferedReader is=new BufferedReader(new
            InputStreamReader(new FileInputStream(FileName)));
    String s;
    boolean more=true;
       while(more){
            s=is.readLine();
Why is this happening?
0
jc31415
Asked:
jc31415
1 Solution
 
heyhey_Commented:
compare the first and second (modified) file with hex editor.
0
 
mbormannCommented:
have u tried this
while((s=is.readLine())!=null)
{}

instead of this
>>>>>while(more){
s=is.readLine();

?
0
 
jc31415Author Commented:
I was writing my lines with +"\n\r". When I changed to +"\r", the problem was fixed.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now