文件存在时抛出FileNotFoundException [英] FileNotFoundException thrown when the file does exists

查看:159
本文介绍了文件存在时抛出FileNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临这个奇怪的问题。

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

当我运行一个独立的应用程序(16行java文件)时,一切都很好。但是当我尝试使用相同的类和相同的方法从服务器引擎(这是一个应用程序引擎,就像你可以运行java程序的Java EE应用程序服务器)中读取相同的文件时,FileNotFoundException抛出。

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.

我虽然会有某种权限,所以我将资源映射为驱动器:K:\

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

重新运行我的java文件,读取,正常。

Re-run my java file, reads, fine.

在engine - > FileNotFoundException中重新运行我的java文件。

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

当我将文件复制到本地机器(C:\ MyFileHere.txt)时,不会抛出任何异常。

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

问题

可能导致此FileNotFoundExcecption的原因是什么?

What may be causing this FileNotFoundExcecption?

我正在使用Java 1.5

I'm using Java 1.5

据我所知,引擎几乎透明地使用java。

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

任何人都遇到类似的事情?

Anyone has faced something similar?

其他问题?这对解决方法有什么好处?我开始考虑提供服务这些文件的tomcat安装并通过http读取它们,但我认为这太多了,这就是为什么SMB协议首先出现的原因不是吗?也许我无论如何都无法打开套接字。

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 )

如果出现这种情况,是否会抛出SecurityException?

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

非常感谢。

编辑

解决了。谢谢Steve W。

Solved. Thank you Steve W.

事实证明这个引擎是用ZeroG的LaunchAnywhere启动的。因此,创建一个.exe,然后将使用指定的应用程序运行JVM。

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.

这个应用程序本身就是Launcher。当它启动引擎时,以某种方式(我无法弄清楚为什么或如何)拥有JVM进程的用户是SYSTEM。史蒂夫指出,该用户没有NETWORK访问权限,因此无法从共享资源或映射驱动器中读取。

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.

解决方法(我向制造商报告时)是创建一个.cmd文件来手动启动引擎。由于它是手动启动的,因此用户可以访问网络。

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.

我使用了SysInternals的Process Explorer来确切地知道用于运行的命令行引擎应用。

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

什么是MESS!

感谢那些发布答案的人。

Thanks to those who posted answers.

推荐答案

共享资源是否受用户名和密码保护?如果是这样,您的应用程序引擎是否以该用户身份运行?如果您的应用程序引擎作为Windows服务运行,则Windows服务无法作为本地系统帐户运行。此帐户无法访问网络。您必须将服务配置为以具有访问共享驱动器权限的用户身份运行。

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.

这篇关于文件存在时抛出FileNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆