Java System Properties
Quick Reference Guide

file.encoding Java System Property

The file.encoding java system property determines the default file encoding to use

Default Value


Overview of file.encoding

The file.encoding system property specifies the default file encoding used by java.

Related System Properties

Here are some other File related Java system properties:

Supported Since

Java has supported the file.encoding system property since as far back as we can remember.

Setting file.encoding on Startup

You 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:


Setting / Reading file.encoding at Runtime

You 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");