• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BufferedReader not reading first character

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am reading from a file using this
String strLine = inputFile.readLine();

This file is an xml and so the first character in the file is "<".
When I write the string back to another file using
FileOutputStream, the first character alone is not written.

One work around I can think of is appending the "<" first to the file before continuing to write the file using outputstream, which I guess is not the right thing to do

Is there any proper way to fix this problem?

Thank u!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't look for a way to patch the symptom -- look for what's causing the problem. The only way this would happen is if someplace you're calling "read()" to read a single character from the beginning of the file. Find that, and remove it or otherwise deal with it.
 
vivek ja
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I was using a inputFile.read() to check for end of the file.
Thats why it wasnt working.

Now am using while ((myStr=inputXmlFile.readLine())!=null)

It works now!

Thanks!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic