开发者

doubt in file path

开发者 https://www.devze.com 2023-01-20 18:29 出处:网络
i tried a program comparing C:\\Program Files and C://Program Files i checked with compareTo()==0 it comes they are equal. But i doubt if there is any difference between //&\\

i tried a program comparing C:\Program Files and C://Program Files i checked with compareTo()==0 it comes they are equal. But i doubt if there is any difference between //&\ Is t开发者_如何学Gohere any difference? what is the difference between c:/program files and //?


There is no difference, at least in Sun's implementation. The Win32FileSystem normalizes paths by converting slashes and removing duplicate slashes.

If you want to be 100% portable, use File.separator


The separator between path components depends on operating system. Java represents file path independently of operating system and that causes equality of values considered. Conversion to native representation is done on lower level (as Bozho pointed out), and you should not worry about that. Nevertheless I'd recommend using "/" as separator, as it is more common OS-wise.

0

精彩评论

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

关注公众号