The File class contains the following public members that you can use for platform specific file paths:
static String pathSeparator:
The system-dependent path-separator character, represented as a string for convenience. static char pathSeparatorChar:
The system-dependent path-separator character. static String separator:
The system-dependent default name-separator character, represented as a string for convenience.
static char separatorChar:
The system-dependent default name-separator character.
You can use any path separator in Java, it will work on both Unix and Windows.
If you still want to use the system path separator there is the File.separator property which will give you the right one depending on the current system.
For the root, you can use listRoots() which gives you an array of root, there will be only one element on Unix systems, and as many as you have drives on Windows.
Personally, I like to use the Path class from Eclipse for handling paths in general, which you can just use standalone with few modifications as it's quite isolated.
Only 10 years too late....
The "It doesn't matter just use '/'" is only half true (ok, three quarters). You have to think about where your data is coming from.
If you get a path in Java, it will use '/'
If you create a path in Java it will understand '/'
But what about paths that are input to your program?
Suppose I have a series of scripts that create a config (Properties) file. Suppose one of the config variables is INTERESTING_FILE, and we generate this to be a filename including path. Now suppose I want to extract the actual Filename from that, so I say