我做到這一點,寫一些內容到這個文件。FileNotFoundException異常的CanRead雖然()和存在()返回true
fileSymbol = new File("D:\\TempFiles\\SymbolFile.xml");
fileSymbol.createNewFile();
prSymbol = new PrintWriter(fileSymbol);
while(//condition goes here){
prSymbol.write(text);
}
然後我嘗試從這個文件讀取,
FileReader fr = new FileReader(fileSymbol);
BufferedReader br = new BufferedReader(fr);
String line = br.readLine();
當我嘗試運行,它提供了以下異常
java.io.FileNotFoundException: fileSymbol (The system cannot find the file specified)
當我嘗試
fileSymbol.canRead();
fileSymbol.exists();
對兩者都返回true。
我不明白爲什麼我得到這個錯誤,雖然我已經創建的文件。當我手動檢查位置時,我能夠看到我創建的文件。
PS:我剛纔提供我的代碼的代碼段。
您關閉了'prSymbol'嗎?它可能會鎖定文件。 – Vulcan 2013-03-07 06:08:17
@Vulcan是的。我已經關閉它,然後像prSymbol.close()一樣讀取它。 – Prasanna 2013-03-07 06:19:57
不重複。該問題涉及編譯錯誤。 – dty 2013-03-07 09:52:42