aspose file tools*
The moose likes I/O and Streams and the fly likes File dir = new File( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "File dir = new File("\\server\log\");" Watch "File dir = new File("\\server\log\");" New topic
Author

File dir = new File("\\server\log\");

Eugene Wong
Greenhorn

Joined: Mar 05, 2007
Posts: 11
File dir = new File("\\server\log\");
String[] list = dir.list();

Could someone tell me why dir.list() would returns null? It does not when I run my web app from netbeans' tomcat 5.5, but when I deploy my project onto the real apache tomcat 5.5, it could not find the folder. I am running both netbeans and tomcat are the same machine and dir.exists() returns true on netbeans, but false on tomcat. any help would be great, thanks in advance.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42913
    
  68
Is there possible a security manager present on Tomcat that prevents it from accessing the directory?
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Originally posted by Ulf Dittmer:
Is there possible a security manager present on Tomcat that prevents it from accessing the directory?


Hi Ulf, may be i am wrong, but if there is a security manager, would not the list() method throw a SecurityException?


apigee, a better way to API!
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Looks like, the path you are using is a relative path. So, it will depend on the directory you are running the program in. If it changes which i am sure it does from your IDE to tomcat, it will not be able to find the directory.
Eugene Wong
Greenhorn

Joined: Mar 05, 2007
Posts: 11
Thanks all for your replies.

First of all, there is no Exception being threw here, it returns null and the program continues on it own

Nitesh, I am trying to access a directory which is shared on \\server\log\ (Windows), I don't think it is relative path thats causing this problem. I have tried using \\\\server\\log\\, still no luck.

any help is appreicated.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Sorry to keep hammering on relative path but that's where I usually get confused ... When I use relative paths like that I often log the File.getCanonicalPath (or one of those) just to make sure it is where I think it is. Have you double checked it that way?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Eugene Wong
Greenhorn

Joined: Mar 05, 2007
Posts: 11
Found the solution, it suggested to start the tomcat service as administrator, rather than Local System.

Problem solved, thanks everyone.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File dir = new File("\\server\log\");