开发者

Java .isDirectory() return true also on file without extension

I've noticed that checking if an instance of a File class is a Directory with the method isDirectory() this method return true also for file without an extension .

For example if i have a file name myfile without exetension isDirec开发者_StackOverflow社区tory() method return true, is there another method that check if the file passed is really a directory ?

I'm trying on Windows ...


Works properly on my Windows7, JDK 6. Try upgrading your JRE/JDK and double-check if you don't have a directory with the same name. I used this snippet to check:

File file = new File("C:\\tomcat\\apache-tomcat-7.0.20\\LICENSE");
System.out.println(file.isDirectory()); // prints false


I've tried Windows 7 32 bit, 64 bit with JDK 6 and 7 and on both of those it works absolutely fine for me. Can't find any bug reports of this nature around either, what code are you using? I very much doubt this is a bug that's gone undiscovered up until now!


Perhaps the directory contains both a file with extension and a directory with the same name but without extension. Then configure the Windows file explorer to hide the extension, think that that is displayed is the real and full name of the file, put that into some test code ... Bingo.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜