簡體   English   中英

fileNotFoundException但文件存在

[英]fileNotFoundException but file exists

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

如果我將鏈接從異常復制到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);

出於安全原因,我更改了鏈接

你應該用

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

而不是FileInputStream

請參閱異常消息...可能您沒有權限“java.io.FileNotFoundException(Permission Denied)”。 您必須授予當前運行該應用程序的用戶的權限。

您是否將FileInputStream作為字符串提供給URL? 然后你正在使用 ,它說:

通過打開與實際文件的連接來創建FileInputStream,該文件由文件系統中的路徑名稱命名。

也許您寧願使用URL.openStream() ,它可以在任何類型的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.

你確定,那里提到的任何一個場景都沒有發生?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM