I used to know it, but I know there is a way in java to make sure the path works in all OSs (Windows uses a different "/" system than Unix based systems). What do I have to do to create a file path name that works with all systems?
EDIT: I wasn't sure if this is what I meant, but I think the file path will end up being relative.
Also, what's the difference between File.separator and File.pat开发者_StackOverflow社区hSeparator ?
You'll have to use File.separator
or File.separatorChar
for this purpose.
Check the File
class javadoc for more info on this.
edit:
Difference between separator
and pathSeparator
. The first separates the folder in a file's path like the /
in /usr/bin
. The second one is a separator in a path
environment variable, like the ;
in PATH=C:/windows/bin;C:/anotherfolder
You can just use /
(forward slash) as the path separator. That will work cross-platform.
File
has a separator
I've used this before, except I'm not sure of its popularity.
System.getProperty("file.separator");
精彩评论