Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BufferedReader.readLine() skips lines

 
Oliver Moore
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm reading a file using BufferedReader.readline(). I've noticed that the formatting of the file you're trying to read has to be spaced by carrage returns!! Is this correct behaviour?

My Code is:



If my text file is formatted as follows, only test2 and null will be output.

Start Of File
test1
test2
test3
EOF

However, if I format it as follows, test1, test2 and test3 will be output.

Start Of File
*carriage return
test1
*carriage return
test2
*carriage return
test3
EOF

Utilmately, this can be solved by carefully formatting my input first, but can anyone explain if it's an inherant Java problem or my code.

Thanks!!
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like, why are you reading the lines of your file twice in your while loop?
 
Oliver Moore
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah... that's the exact problem.... thanks...

First time I've played with IO...
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't worry, done it myself once
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic