路径正确下,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ㄒ)/~~)

原文地址:https://www.cnblogs.com/ticktack/p/6596622.html