• Post Reply Bookmark Topic Watch Topic
  • New Topic

junk added at the end of file  RSS feed

 
Abhishek Dhama
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am using PrintWriter over an FileOutputStream to write some strings
in a file. But the problem is in , writer appends some junk character
at the end of file which I dont want. I believe it is either because of
flusing or character encoding. I am enclosing the code, any suggestions?

<code>

try {
datalogwriter.println(sfact);
} catch (NullPointerException npe) {
System.out
.println("Exception in DatalogFileGenerator.putFact(...):"
+ npe.getMessage());
} finally {
if (datalogwriter.checkError())
throw new IOException(
"IOException:Couldnt write fact to datalog file");
}

</code>

tar
/abhishek
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What "junk" are you talking about? I'd be willing to bet you are looking at the line separator characters that are appended to whatever you write with a call to println().
 
Abhishek Dhama
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for reply. But the problem was elsewhere. The string I was writing to the file had some trailing blank places and these were printed as junk.

tar
~/abhishek
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!