Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I posted this question in Stack Overflow, and someone redirected me here:

Hello everyone. I'm doing a Windows Service in Java, this service list the files in a directory and write the results in a file. My problem is that when i call Java.File.isDirectory() when the service is running it always results false (It works well when i run the service manually as any other program). Besides, if i try the following: for(File F : directorio.listFiles()) trows an exception when i run the program as a service. I believe is permission related, because when i change the account in which the service is running to my own credentials it list the files correctly. Do you know if there is a workaround? (Change a windows policy, another kind of special account, another way to list the files of the directory, any other thing maybe i'm missing). Thanks in advance.

share|improve this question

Thanks for all your help! I found my problem, i was reading the path from a configuration file which i assumed to be in the user's home (my home and System's home are not the same... my fault). Unfourtenly i didn't realize that because i was using a recycled class (:S). Again Thank you very much.

share|improve this answer

Based on the documentation for File.isDirectory(), it sounds like you may have a security manager enabled. isDirectory requires the checkRead permission to be enabled, and you can test this yourself by using the something like the following (edit as needed):

SecurityManager security = System.getSecurityManager();
        // we have permission
        // no permission

Adding the directory to the list of allowed directories may or may not be on your list of things to do. There are dozens of Google links with instructions if this is the case. The same goes if you would like to disable the SM completely.

share|improve this answer
Another curious thing, i don't have a Security Manager (System.getSecurityManager() returns null) but i found that the Access Controller forbids me from reading a file no matter my credentials, this code always trows an exception: – Rafael Nov 1 '10 at 18:14
FilePermission perm = new FilePermission("MyDir", "read"); try { AccessController.checkPermission(perm); message="Allowed"; } catch (AccessControlException accessControlException) { message="Disallowed"+accessControlException.getMessage(); } – Rafael Nov 1 '10 at 18:15
Then it sounds like your user doesn't have file-system level access to the files in question. – Andrew M. Nov 2 '10 at 3:36
The strange thing is that this directory is in my home directory, and i'm running the program above with my own credentials. – Rafael Nov 4 '10 at 2:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.