The file.encoding
system property specifies the default file encoding used by java.
Here are some other File related Java system properties:
Java has supported the file.encoding
system property since as far back as we can remember.
file.encoding
on StartupYou can set the file.encoding
java system property during startup of the java runtime using the -D
command line argument:
java -Dfile.encoding=UTF-8 MyAppMain
You may also be able to specify file.encoding
via the JAVA_TOOL_OPTIONS
environment variable:
JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
file.encoding
at RuntimeYou can set file.encoding at runtime with the following Java code:
System.setProperty("file.encoding", "UTF-8");
WARNING: Depending on the property and JVM version using
setProperty
may or may not work if the JDK Java class that uses this variable has already been loaded. The value of the file.encoding system property may be cached within an internal private static variable of the implementing class.
To read the value of file.encoding at runtime, you can use this Java code:
String propertyValue = System.getProperty("file.encoding"); if (propertyValue != null) { System.out.println("file.encoding = " + propertyValue); } else { System.out.println("file.encoding was null"); }