Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ObjectOutputStream

 
Frank Daly
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My code produces a text file based on a string. However when I run the code, i get some unexpected characters prepended to the string.
relevant code...
String test = new String("hope");
ObjectOutputStream oos = new ObjectOutputStream (new FileOutputStream("results.txt"));
oos.writeObject(test);
oos.close
produces the following text in the results.txt file
�� t hope
any reasons for the above, and any ways to eliminate the offending chatacters, would be appreciated.
frank
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of using ObjectOutputStream, why not use a Reader or Writer since you are working with Strings. ObjectOutputStream is better when you have to write out complex objects, not strings. A Reader and a Writer will write out and read back strings like you want.
Bill
 
Frank Daly
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!