The file.separator system property can be useful to determine how to separate files and directories when constructing paths.
Here are some other File Path Java system properties:
Java has supported the file.separator system property since as far back as we can remember.
file.separator on StartupYou 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=/
file.separator at RuntimeYou can set file.separator at runtime with the following Java code:
System.setProperty("file.separator", "/");
WARNING: Depending on the property and JVM version using
setPropertymay 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");
}