Java file construction - why am I getting different results?
I've just stumbled on a weird scenario and am wondering if anyone can explain this behaviour.
Case 1:
File base = 开发者_JAVA技巧new File("");
System.out.println(base.getAbsolutePath());
System.out.println(base.isDirectory());
System.out.println(base.canRead());
Result:
C:\workspace-sss\Commons
false
false
Case 2:
File base = new File("C:/workspace-sss/Commons");
System.out.println(base.getAbsolutePath());
System.out.println(base.isDirectory());
System.out.println(base.canRead());
Result:
C:\workspace-sss\Commons
true
true
If the absolute path of the two File objects are equal, why are they treated differently?
If you used new File("."), you should get the correct results for the current directory.
加载中,请稍侯......
精彩评论