Eclipse - 打印文件进入控制台

Eclipse - Print file's entry into console

我有一些包含大量数字的文件(测试输入),所以我想以某种方式打印它以进行控制台。

但是如果我转到 运行 配置并将 InputFile: 设置为 input.txt 然后控制台 returns:

[为标准输入文件指定的文件无效:input.txt]

有人知道问题出在哪里吗?

我不确定您想如何访问您的输入文件。据我所知,没有允许将文件用作 System.in 的 eclipse 功能。 (见 Eclipse reading stdin (System.in) from a file

我尝试重现您的 eclipse 设置(如您的评论中所述)并构建了一个简单的程序,输出输入的每一行。

Java8:

public class Main {

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

        // get resource from classpath
        URL resource = ClassLoader.getSystemResource("quickfind/largeUF.txt");
        Path path = Paths.get(resource.toURI());

        // read all lines
        List<String> allLines = Files.readAllLines(path);

        // print all lines
        allLines.stream().forEach(System.out::println);
    }
}

Java7:

public class Main {

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

        // get resource from classpath
        URL resource = ClassLoader.getSystemResource("quickfind/largeUF.txt");
        Path path = Paths.get(resource.toURI());

        // read all lines
        List<String> allLines = Files.readAllLines(path);

        // print all lines
        for (String line : allLines) {
            System.out.println(line);
        }
    }
}