【问题标题】:Running code in Eclipse with additional input [duplicate]使用附加输入在 Eclipse 中运行代码 [重复]
【发布时间】:2017-10-21 03:23:26
【问题描述】:

在我的 CS 课程中,我们使用终端来运行我们的代码,使用 javac 来 cimpile 和 java 来运行。 在我目前的作业中,我正在接收来自文件的输入。在 CMD(终端)中输入命令时会给出文件名,如下所示: “java -cp mypath\class text.txt” 使用此代码:

if (args.length != 1) {
        final String msg = "Usage: EmployeePay name_of_input file";
        System.err.println(msg);
        throw new IllegalArgumentException(msg);
    }
    final String inputFileName = args[0];
    final File input = new File (inputFileName); 
    final Scanner in = new Scanner (input);

当用 Eclipse 运行它时,它会抛出异常。 eclipse 中有没有办法在不更改或向代码本身添加任何内容的情况下执行此命令“java -cp mypath\class text.txt”?

【问题讨论】:

    标签: java eclipse terminal


    【解决方案1】:

    转到Run/Run configurations...,然后在左侧选择您的“运行实例”,然后选择Arguments 标签,最后在Program arguments 中输入您的text.txt场地。单击Apply 并为其他“运行实例”重复此操作(如果有)。

    如果你想运行你的项目,可以点击Run,但是不要忘记事先点击Apply...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-16
      • 1970-01-01
      • 2017-07-30
      • 2014-11-18
      • 1970-01-01
      • 2013-06-28
      • 2013-02-17
      相关资源
      最近更新 更多