FileNotFoundException thrown when the file does exists

OscarRyz picture OscarRyz · Jan 28, 2009 · Viewed 7.3k times · Source

I'm facing this strange problem.

I'm trying to read a file that is located in another machine as a shared resource:

\\remote-machine\dir\MyFileHere.txt

When I run a standalone application ( a 16 lines java file ) everything is just fine. But when I attempt to read the same file with using the same class and the same method from a server "engine" ( this is an application engine, pretty much like a Java EE Application Server where you can run java programs ) the "FileNotFoundException" is thrown.

I though I would be some sort of permissions, so I map the resource as a drive: K:\

Re-run my java file, reads, fine.

Re-run my java file inside the "engine" -> FileNotFoundException.

When I copy the file into the local machine ( C:\MyFileHere.txt ) no exception is thrown.

Question

What may be causing this FileNotFoundExcecption?

I'm using Java 1.5

As far as I know the engine pretty much uses java transparently.

Anyone has faced something similar?

Additional question? What would be a good approach for workaround this? I'm starting to think about a tomcat installation serving those files and read them through http, but I think that's too much, that's why the SMB protocol is for in first place isn't it? And probably I won't be able to open sockets anyway.

Does security manager may be the cause ( I have never used that before, but I know it exists )

Wound't a SecurityException be thrown instead if that would be the case?

Thanks a lot.

EDIT

Solved. Thank you Steve W.

It turns out that this engine is launched with "LaunchAnywhere" from ZeroG. So, a .exe is created that in turn will run a JVM with the specified app.

This application it self is Launcher. When it start the engine, somehow ( I cannot figure out why or how ) the user that owns the JVM process is SYSTEM. AS Steve pointed out, this user doesn't have NETWORK access, and thus cannot read from a shared resource or a mapped drive.

The workaround ( while I report this to the manufacturer ) is to create a .cmd file to lauch manually the engine. Since it would be manually launched the user does have access to the network.

I've used "Process Explorer" from SysInternals to know exactly the command line used to run the engine app.

WHAT A MESS!

Thanks to those who posted answers.

Answer

Steve Wranovsky picture Steve Wranovsky · Jan 28, 2009

Is the shared resource protected by a username and password? And if so, is your application engine running as that user? If your application engine is running as a Windows Service, the Windows service cannot be running as the "Local System Account". This account cannot access the network. You must configure your service to run as a user that has the rights to access the shared drive.