小编use*_*723的帖子

eclipse中的java.io.FileNotFoundException

码:

import java.io.*;
import java.util.Scanner;

public class Driver {

    private int colorStrength;
    private String color;

    public static void main(String[] args) throws IOException {

        String line, file = "strength.txt";

        File openFile = new File(file);
        Scanner inFile = new Scanner(openFile);

        while (inFile.hasNext()) {
            line = inFile.nextLine();
            System.out.println(line);
        }

        inFile.close();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我为一个类编写的程序的一小部分(我知道这两个私有属性尚未使用)但是当我尝试使用strength.txt文件运行它时,我收到以下错误:

例外:

Exception in thread "main" java.io.FileNotFoundException: strength.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 Driver.main(Driver.java:14)
Run Code Online (Sandbox Code Playgroud)

如果有人用Eclipse可以帮我解决这个问题,我将不胜感激!

java eclipse filenotfoundexception

9
推荐指数
1
解决办法
4万
查看次数

标签 统计

eclipse ×1

filenotfoundexception ×1

java ×1