fileNotFoundException但文件存在

时间:2011-11-29 12:39:14

标签: java file filenotfoundexception

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

如果我将链接从异常复制到webbrowser,它也有效。 对于每个人来说,RWX都有权利进行测试,但这没有用。

文件名中没有特殊标志...... 我不知道为什么会失败..

thx 4 help!

编辑:

KeyStore ts = KeyStore.getInstance("PKCS12");
ts.load(new FileInputStream("http://192.168.1.1/ordner/myFile.p12"), passwKey);
KeyManagerFactory tmf = KeyManagerFactory.getInstance("SunX509");
tmf.init(ts, passwKey);

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

4 个答案:

答案 0 :(得分:6)

你应该使用

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

而不是FileInputStream

答案 1 :(得分:1)

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

答案 2 :(得分:1)

您是否将FileInputStream作为String提供?然后你正在使用this并声明:

  

通过打开与实际文件的连接来创建FileInputStream,该文件是由文件系统中的路径名称命名的文件。

也许你宁愿使用URL.openStream(),它可以用于任何类型的网址,包括远程网址。

答案 3 :(得分:1)

来自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.

你确定,那里提到的任何一个场景都没有出现吗?