tags:

views:

418

answers:

3

Please see code snippet:

File[] additionalFiles = new File(FILE_PATH).listFiles();
boolean isDirectory = file.isDirectory();

I have verified that the directory path is correct, and when I run the code on Windows, the value of isDirectory is true (as it should be). Any suggestions as to why this occurs on Linux (RedHat Enterprise Linux)?

+1  A: 

Symlinks don't read as directories, if I remember correctly. The right way around that is:

 new File(FILE_PATH).getCanonicalFile().isDirectory(); 

(NOTE: Untested, I don't have a linux box to test this on easily).

Yishai
A: 

Checkout this link http://bugs.sun.com/view_bug.do;jsessionid=56e03cb783aaf9725daf5ec8d8?bug_id=6539692

You may have this issue.

Otherwise I would guess an issue with file permissions (though that might throw back security exception and I am assuming your code does not wrap it and return false) or may be a sym link issue that I dont know much about.

Fazal
A: 

I'm experiencing the same issue as well. I'm using Ubuntu 9.10 and Java 6.

new File("/etc/hosts").isDirectory()

returns true for me even if that file is very well known in the unix world as the hosts file, not directory.

GCG