【问题标题】:fileNotFoundException but file existsfileNotFoundException 但文件存在
【发布时间】:2011-11-29 12:39:14
【问题描述】:

在我的 FileInputStream 中,我得到一个 FileNotFoundException, 但我知道他的文件存在,我可以用网络浏览器下载。

如果我将链接从异常复制到 webbrowser,它也可以工作。 每个人都可以在 RWX 上进行测试,但这无济于事。

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

thx 4 帮助!

编辑:

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);

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

【问题讨论】:

  • 所以您正在尝试将 FileInputStream 用于服务器上的文件?此外,发布您的代码可能会有所帮助。
  • 您能发布您的代码吗?
  • 发布实际的错误信息 -- 复制/粘贴。

标签: java file filenotfoundexception


【解决方案1】:

你应该使用

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

而不是FileInputStream

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      你是否给 FileInputStream 一个 URL 作为字符串?然后你正在使用this 它声明:

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

      也许您更愿意使用URL.openStream(),它适用于任何类型的 URL,包括远程 URL。

      【讨论】:

        【解决方案4】:

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

        你确定那里提到的任何场景都没有发生吗?

        【讨论】:

          猜你喜欢
          • 2015-02-20
          • 2013-10-18
          相关资源
          最近更新 更多