我的代碼非常簡單直接。我使用PrintWriter
類創建一個空文件,並將數字1 - 100寫入文件,然後關閉文件。據我所知,PrintWriter
應該創建空文件,這讓我想知道爲什麼我得到這個FileNotFoundException
錯誤。未處理的異常類型FileNotFoundException(出於某種奇怪的原因)
public class Practice {
public static void main(String[] args){
PrintWriter outputFile = new PrintWriter("nums.txt");
for(int i = 0; i < 100; i++)
outputFile.println(i + 1);
out.close();
}
}
你是顯示的代碼不可能有可能拋出'FileNotFoundException'。 –
你能顯示完整的錯誤信息嗎? – Aaron
也許您嘗試在只讀目錄中執行代碼。你可以檢查一下嗎? –