Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

BufferedReader not reading first character  RSS feed

 
vivek ja
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • 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!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!