【发布时间】: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”?
【问题讨论】: