0

In my CS class we use the terminal to run our codes, using the javac to cimpile and java to run. In my current assignment I'm receiving inputs from a file. The name of the file is given when inputing the command in the CMD (terminal) like this: "java -cp mypath\class text.txt" using this code:

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);

When running this with Eclipse, it throws the Exception. Is there a way in eclipse to do this command "java -cp mypath\class text.txt" without changing or adding anything to the code itself?

Tom
  • 5
  • 4

1 Answers1

0

Go to Run/Run configurations..., then select your "run instance" in the left, then select the Arguments tab and finally enter your text.txt into the Program arguments field. Click Apply and repeat that for the other "run instances" if any.

You may click Run if you want to run your project, but do not forget tto click Apply beforehand...

Usagi Miyamoto
  • 6,196
  • 1
  • 19
  • 33