Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java fileNotFoundException但文件存在_Java_File_Filenotfoundexception - Fatal编程技术网

Java fileNotFoundException但文件存在

Java fileNotFoundException但文件存在,java,file,filenotfoundexception,Java,File,Filenotfoundexception,在我的FileInputStream中,我得到一个FileNotFoundException, 但我知道文件存在,我可以用webbrowser下载 如果我将链接从异常复制到webbrowser,它也可以工作。 每个人都有权在RWX上进行测试,但这没有帮助 文件名中没有特殊符号。。。 我不知道为什么会失败 thx 4帮助 编辑: 出于安全原因,我更改了链接请参阅异常消息。。。可能您没有权限“java.io.FileNotFoundException(权限被拒绝)”。您必须向当前运行应用程序的用户授

在我的FileInputStream中,我得到一个FileNotFoundException, 但我知道文件存在,我可以用webbrowser下载

如果我将链接从异常复制到webbrowser,它也可以工作。 每个人都有权在RWX上进行测试,但这没有帮助

文件名中没有特殊符号。。。 我不知道为什么会失败

thx 4帮助

编辑:


出于安全原因,我更改了链接

请参阅异常消息。。。可能您没有权限“java.io.FileNotFoundException(权限被拒绝)”。您必须向当前运行应用程序的用户授予权限。

您是否将URL作为字符串提供给FileInputStream?然后您正在使用,并且它声明:

通过打开与实际文件(文件系统中以路径名命名的文件)的连接来创建FileInputStream


也许您更愿意使用它来处理任何类型的URL,包括远程URL。

来自Java规范:

Signals that an attempt to open the file denoted by a specified pathname has failed. 

This exception will be thrown by the FileInputStream, FileOutputStream, and RandomAccessFile constructors when a file with the specified pathname does not exist. It will also be thrown by these constructors if the file does exist but for some reason is inaccessible, for example when an attempt is made to open a read-only file for writing.
您确定没有发生您提到的任何场景吗?

您应该使用

InputStream is = new URL("http://stackoverflow.com/").openStream();

因此,您尝试对服务器上的文件使用FileInputStream,而不是
FileInputStream

?此外,发布代码可能会有所帮助。请发布代码好吗?发布实际的错误消息--复制/粘贴。
InputStream is = new URL("http://stackoverflow.com/").openStream();