I am writing into a java file through
FileWriter fstream = new FileWriter("someFile.java");
BufferedWriter out = new BufferedWriter(fstream);
out.write(strContents);
// Close the output stream
out.close();
but after writing I found it appended some special characters in shape of box like [], but those special characters are only visible in specific text editor like EditPlus.
How to avoid those special characters while writing or is it specific to some editors only.
My advice would be to avoid using
FileWritercompletely. It always uses the platform default encoding, which is rarely a good idea.I would suggest using
FileOutputStreamwrapped in anOutputStreamWriter– then you just need to specify an appropriate encoding, such as UTF-8. Obviously you’ll still need to use an editor which supports UTF-8, and you may need to tell it the encoding… but at least you’ll have code which always writes in the same way, regardless of OS and system properties.