Sadly, the file.encoding property has to be defined as the JVM starts up; by the time your main program is entered, the character encoding practiced by String.getBytes() and the default constructors of InputStreamReader and OutputStreamWriter has been lastingly cached.
in a particular case like this, the environment variable JAVA_TOOL_OPTIONS can be used to define this property, but it's usually done like this:
java -Dfile.encoding=UTF-8 … com.x.Main
Charset.defaultCharset() will reflect adjustments to the file.encoding property, but most of the code in the focus Java libraries that need to define the default character encoding does not apply this tool.
When you are encoding or decoding, you can question the file.encoding property or Charset.defaultCharset() to detect the current default encoding, and try the relevant method or constructor overload to define it.