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.pathSeparator ?
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
带有分隔符
除了不确定它的受欢迎程度外,我以前已经使用过它。
System.getProperty("file.separator");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.