症狀:使用Eclipse讀取文件時,路徑輸入確認正確(前提!!!),但控制台總報錯:
錯誤類型一:
Exception in thread "main" java.io.FileNotFoundException: file.txt (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(Unknown Source) at java.util.Scanner.<init>(Unknown Source) at helloworld.main(helloworld.java:9)
錯誤類型二:“文件名,目標名,或卷積語法不正確”
錯誤類型三:讀取的文件為空
原因:text file encoding修改過,導致無法讀取txt文件
解決方法:在Window-Preferences-General-Workspace中,將Workspace頁面左下角的Text file encoding改為默認的Default(GBK),其他編碼方式不確定是否可以。(博主之前修改成UTF-8格式后,就讀不了文件了/(ㄒoㄒ)/~~)