开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜