ObjectOutputStream
is used to write Java objects to a stream. That means won't write the value of a String into the stream; instead if will write "the next object is a String
and the value for it is SomeObject
".
So if you want a plain text file, you have to use the Writer
API.
Note: Your code is platform dependent. If you want to make it platform independent, then you have to use:
FileOutputStream stream = new FileOutputStream( file );
return new BufferedWriter( new OutputStreamWriter( stream, Charset.forName("UTF-8") ) );