【问题标题】:Eclipse - Print file's entry into consoleEclipse - 将文件的条目打印到控制台
【发布时间】:2015-09-06 05:26:00
【问题描述】:

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

但是如果我去运行配置并将 InputFile: 设置为 input.txt 然后控制台返回:

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

有人知道是什么问题吗?

【问题讨论】:

  • 您硬盘上的input.txt 位于何处?您的启动配置使用哪个工作目录?
  • dodaj.rs/f/n/vk/2EEvHe1N/untitled.png 这是照片,我不确定“您的启动配置使用哪个工作目录?”是什么意思

标签: eclipse file input console output


【解决方案1】:

我不确定你想如何访问你的输入文件。据我所知,没有 Eclipse 功能允许将文件用作System.in。 (见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);
        }
    }
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-27
  • 1970-01-01
  • 2021-06-05
  • 1970-01-01
  • 2022-12-04
  • 2012-06-01
  • 1970-01-01
相关资源
最近更新 更多