The default is the derived from the underlying OS. It can be overridden by a system property (file.encoding).
Since both of these are kind of outside of your control, it is probably better to explicitly specify an encoding for all the files your program writes and read. UTF-8 should work in most cases.
Stream tostring() method uses JVM default encoding, which JVM gets from the current OS if not explicitly specified.
byteArrayOutputStream baos = new ByteArrayOutputStream(); ...do something baos.toString();
if the outputString uses UTF-8 and it is in windows, given there are extended chars, it would messed up.
- we can explicitly say outputStream.toString(“UTF-8”);
- we can also run our JVM using parameter: java -Dfile.encoding=UTF8 myClass