路徑正確下,Eclipse讀取txt文件仍失敗


症狀:使用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ㄒ)/~~)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM