日期:2014-05-20  浏览次数:20617 次

File file = new File(D:\test\a.txt) 文件存在 但是file.exists()为false
如题
File   file   =   new   File(D:\test\a.txt)
if(!file.exists())
    System.out.println( "file   is   not   exist ");
else
    System.out.println( "file   is   exist ");
我的d盘的test的目录下明明有a.txt这个文件,为什么打印出来却是文件不存在呢?
另外我如果用JFileChooser来选择文件,然后再用上边的语句,就可以打印出文件存在,非常奇怪。

------解决方案--------------------
File file = new File( "D:\\test\\a.txt ")
------解决方案--------------------
字符串中反斜杠\需要转义字符\\
------解决方案--------------------
同意三楼!
------解决方案--------------------
D:/test/a.txt或者D:\\test\\a.txt这样才对