自從我與文件混淆了很長一段時間。我正在嘗試在eclipse中創建一個txt文件,並在此代碼中使用它。處理獲取文件名,查找文件,掃描它的代碼是:從用戶輸入中掃描文件
System.out.println("Input from a file");
System.out.print("Enter file name: ");
String str = expression.nextLine();
int i = 0;
File file = new File(str);
Scanner fScan = new Scanner(file);
我得到的是FileNotFoundExceptions
。我的文件與我的所有課程都在同一個文件夾中,我無法在網上找到真正有用的答案。
因此,如果有人能指出我要去的地方錯了,這將是巨大的:)
請分享項目結構。 – Braj
我相信你的輸入文件路徑是錯誤的。因爲,我沒有問題 – sancho21