java编写文件路径 File.separator 和 "\\”区别
2018-02-09 09:59
597 查看
在windows中的文件分隔符是 \ 和 /都可以 但是在Linux中,文件分隔符只能是/ 所以用了\\的程序在Linux下会出问题。 而File.separator是系统默认的文件分割符号,屏蔽了这些系统的区别。 用File.separator保证了在任何系统下不会出错。源码如下
public Win32FileSystem() { slash = AccessController.doPrivileged( new GetPropertyAction("file.separator")).charAt(0); semicolon = AccessController.doPrivileged( new GetPropertyAction("path.separator")).charAt(0); altSlash = (this.slash == '\\') ? '/' : '\\'; }
相关文章推荐
- java编写文件路径用的File.separator和直接打“\\”有什么区别啊?
- java编写文件路径用的File.separator和直接打“\\”有什么区别啊?
- <input type="file">定义样式并获取上传文件路径及指定文件类型
- java中File文件路径跨平台(File.separator)
- input type="file" 选取文件路径时出现fakepath问题IE浏览器解决办法
- 关于File.separator 文件路径:windows与linux下路径问题 ("\"与"/")
- 关于写入文件缓存时报"java.io.FileNotFoundException open failed (is a director)"错误的解决方法
- "Invalid file name: must contain only [a-z0-9_.]"android项目中R.java文件丢失原因及解决方法.
- Java中获取classpath路径下的资源文件【ClassLoader.getSystemResource("")获取当前ClassPath的绝对URI路径,还可以以流的形式获取文件】
- java中""," ",null之间的区别
- [Python]用Python编写程序修复"恶邮差"变种U病毒感染文件。
- 使用Axis插件来从WSDL文件生成代码时"An error occurred while completing process -java.lang.reflect.InvocationTargetException"的错误
- windows"无法删除****,找不到指定文件,请确定指定的路径及文件名是否正确"的解决
- java写excel文件,报Warning: MS Office Drawing on sheet "Sample" not supported - omitting
- ruby中获取当前脚本文件的路径(Dir.pwd 和 _FILE_ 的区别)
- blackberry 模拟器 上网设置(Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file)
- 文件路径中的“.”,new File(".")
- Java中的String str="abc"; String str=new String("abc");和String str = new String();的区别以及==与equals()的不同。
- Java中"equals"和"=="的区别
- shell "cmd 2>&1 >file" "cmd > file 2>&1" 的区别