Search code examples
javaencodingoutputstreamfilewriterbufferedwriter

Alternatives to setting encoding in FileWriter - Java


I read that java documentation for FileWriter - it doesn't allow us to specify encoding. I'm using FileWriter in order to avoid the newline character that gets automatically appended while writing list of strings to a file(And I think this is the only thing I can use to achieve that).

I'm now facing a problem that some japanese characters in few properties file are written as "???", so I need to pass in the encoding information somehow. Is there any other way to either avoid the newline appending or a way to pass encooding info to FileWriter?


Solution

  • Don't use FileWriter, but instead new OutputStreamWriter(new FileOutputStream(file), encoding).