java.io.FileNotFoundException 没有这样的文件或目录错误但目录存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2376726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:51:17  来源:igfitidea点击:

java.io.FileNotFoundException No such file or directory error but directory exists

javafilenotfoundexception

提问by Atma

I'm getting the filenotfoundexception on my apps directory but my directory clearly exists. I'm doing this on my local machine. I'm doing a very simple post to a servlet. Does anyone knw what could be happening?

我在我的应用程序目录中收到 filenotfoundexception,但我的目录显然存在。我在我的本地机器上这样做。我正在对 servlet 做一个非常简单的帖子。有谁知道会发生什么?

回答by Atma

it turns out this was due to my firewall (firestarter) blocking my servers ip address. I allowed the exception and everything worked.

原来这是由于我的防火墙(firestarter)阻止了我的服务器 IP 地址。我允许例外,一切正常。

回答by TofuBeer

A few of thoughts (hopefully you haven't tried them :-):

一些想法(希望你还没有尝试过:-):

Do you have read access to the directory?

你有目录的读权限吗?

Try putting in something like:

尝试输入以下内容:

System.out.println("the directory = " + directory);

Assuming "directory" is the File variables that holds the directory.

假设“目录”是保存目录的文件变量。

Try putting in something like:

尝试输入以下内容:

System.out.println("the directory exists = " + directory.exists());

and making sure it returns true.

并确保它返回true。

回答by Lawrence Dol

Do you have traversal authority to all intervening path segments, and appropriate authority to the final file?

您是否拥有对所有中间路径段的遍历权限,以及对最终文件的适当权限?