簡體   English   中英

java.io 中似乎缺少 FileNotFoundException class?

[英]The FileNotFoundException class appears to be missing from java.io?

我正在嘗試在 Eclipse 中為學校作業編寫一個簡單的服務器和客戶端。 在某些時候,我需要從客戶端向服務器發送一個文件,並寫下:

File file = new File("./test.png");         
long length = file.length();
byte [] mybytearray  = new byte [(int)length];
FileInputStream fis;
fis = new FileInputStream(file);
                

Eclipse 以紅色突出顯示最后一行,告訴我“構造函數 FileInputStream(File) 引用了缺少的類型 FileNotFoundException”。 經過一些研究和測試,我很確定這不是文件本身的問題。 它存在,可讀,並且不是目錄。 我決定將 class 與

import java.io.FileNotFoundException;

它告訴我“導入 java.io.FileNotFoundException 無法解決”。 It looks to me like Eclipse thinks the class does not exist, but all my other java.io imports are working perfectly fine, and I never messed around in my libraries folder, so I have no idea what the source of the problem is. 我已經嘗試了一些常見的技巧,比如清理我的項目,但我不知道 go 從這里到哪里。

就像,如果我所有的導入都失敗了,那么我顯然做錯了什么,但只有這個失敗的事實很奇怪。

它不太可能不知道java.io.FileNotFoundException ,除非 JDK 安裝已損壞。 try catch Exception (代碼檢查可能會提示):

try {
    fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
    e.printStacktrace();
}

Aaaaaand 我剛重新啟動計算機,問題就消失了。 那好吧。

暫無
暫無

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

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