Java - network directory not file or directory?
Disappointment. This works on the dev box, but not on the production box. This seems to be a permissions issue, but I can't guess (since the network card is open to everyone and accessible from both machines).
I have a directory in a properties file:
- gohere = \\ home \ sub
In my code, I read the directory correctly from the properties file. Here is the code:
File dir = new File(dirFromProperty); // \\\\main\\sub
System.out.println("dirFromProperty = " + dirFromProperty);
System.out.println("dir File = " + dir); //looks right
System.out.println("dir.isDirectory = " + dir.isDirectory()); //false?
System.out.println("dir.isFile = " + dir.isFile()); //false?!
System.out.println("dir.isHidden = " + dir.isHidden()); //false
if(dir.isDirectory()) {
//never gets here
}
It is worth noting:
- This exact code works locally. The moment I start another server, it fails because it thinks it is not a directory. The catalog is available from both machines, 100% confirmed.
Any ideas? I'm going crazy trying to figure out what's going on.
Edit:
Right now it seems to be an issue with Windows Task Scheduler. I can run the application perfectly from CMD. From the task manager, it doesn't recognize the network paths?
Second edit:
I have added a solution to my problem. This is not Java related, it appears to be related to Windows task settings and file access via File class in Java.
source to share
This doesn't seem like a Java issue. This is a Windows problem. Just replace your Java program with a regular Windows process and you will see the same thing. Just extract and show the File / Directory attributes from this process, save them, analyze them and you will see the difference from a Windows perspective.
I am assuming the Task Scheduler is running under a different ID / Access that does not have appropriate access to this network resource. All the signs you describe point to this assumption.
source to share
After much digging, I came to the conclusion that the problem is related to the task itself on the production server.
For some reason, the network path was not recognized as a directory by the File class when I used the following parameter:
- Run whether the user is logged in or not (check do not save the password).
When I unchecked the "Do not store password" checkbox and allowed it to save the password, the network path was recognized. I assume this is because the network path requires you to be logged on to the network (on each server). I assume that this property passed an empty password and therefore no directory.
This is all speculation, but I can 100% confirm it if you canceled the storage password.
source to share