Java System Properties
Quick Reference Guide


file.separator Java System Property

The file.separator java system property determines how file paths are delimited.

Default Value

\ on Windows

/ on Unix, Linux, Mac

Overview of file.separator

The file.separator system property can be useful to determine how to separate files and directories when constructing paths.

Related System Properties

Here are some other File Path Java system properties:

Supported Since

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

Setting file.separator on Startup

You can set the file.separator java system property during startup of the java runtime using the -D command line argument:

java -Dfile.separator=/ MyAppMain

You may also be able to specify file.separator via the JAVA_TOOL_OPTIONS environment variable:

JAVA_TOOL_OPTIONS=-Dfile.separator=/

Setting / Reading file.separator at Runtime

You can set file.separator at runtime with the following Java code:

System.setProperty("file.separator", "/");

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.separator system property may be cached within an internal private static variable of the implementing class.

To read the value of file.separator at runtime, you can use this Java code:

String propertyValue = System.getProperty("file.separator");
if (propertyValue != null) {
    System.out.println("file.separator = " + propertyValue);
} else {
    System.out.println("file.separator was null");
}