2011-11-29 91 views
3

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

如果我將鏈接從例外複製到網頁瀏覽器,它也可以工作。 權利是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); 

我改變了鏈接出於安全原因

+0

所以你正在嘗試使用FileInputStream作爲服務器上的文件?另外,它可能有助於發佈您的代碼。 – mort

+0

可以請你發佈你的代碼嗎? – Unknown

+0

發佈實際的錯誤消息 - 複製/粘貼。 –

回答

6

您應該使用

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

,而不是FileInputStream

+0

多數民衆贊成它! THX現在可以運作! – Starbax

+0

如果我的答案解決了您的問題,請注意/接受它 – mort

+0

我不得不等待5分鐘^^ – Starbax

1

見異常消息......也許你沒有權限「java.io.FileNotFoundException(拒絕)」。您必須向當前運行該應用程序的用戶授予權限。

1

你給FileInputStream一個URL作爲一個字符串?然後你使用this並指出:

創建通過打開一個到實際文件的連接,通過在文件系統中的路徑名名命名的文件一個FileInputStream。

也許你寧願使用URL.openStream()這可以適用於任何種類的URL,包括遠程URL。

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. 

確定,任何之情況的提到有沒有出現?

相關問題