• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

BufferedReader.readLine() skips lines

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't worry, done it myself once
 
reply
    Bookmark Topic Watch Topic
  • New Topic