I know that writers should be used instead of outputstreams when writing text, but still I don't understand why there are extra characters in the file outputStream.txt
after running this program:
public static void main(String[] args) throws FileNotFoundException, IOException
{
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("C:\\Data\\tmp\\outputStream.txt")));
oos.writeObject("SomeObject");
oos.writeUTF("SomeUTF");
oos.flush();
oos.close();
BufferedWriter writer = new BufferedWriter(new FileWriter(new File("C:\\Data\\tmp\\outputWriter.txt")));
writer.write("SomeObject");
writer.write("SomeUTF");
writer.flush();
writer.close();
}
The file outputWriter.txt
is 17bytes, as expected, but outputStream.txt
is 28, including some unrecognizable text. Why is that?