You do not write text to a file, you write objects to it, which means that you get the stream header, type information, and internal structure. To write text, use Writer:
Writer w = new OutputStreamWriter(new FileOutputStream(filename), encoding);
source share