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

相关文章:

  • 2021-11-07
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
  • 2021-09-23
  • 2022-02-10
猜你喜欢
  • 2021-08-09
  • 2022-02-25
  • 2021-05-01
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
  • 2021-09-10
相关资源
相似解决方案