开发者

how do I make path names compatible with different OSs?

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.separatorCharfor 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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜