Java was born as a platform-independent programming language. Some features that provide platform independence are
implemented through the language’s own APIs. For example, to construct a file path, you can use the public static
field separator of the java.io.File class.
Example:
String path = java.io.File.separator + "foldername" + java.io.File.separator + "filename";
This produces the string /foldername/filename on Unix-like systems and \foldername\filename on Windows systems.