2

This is a question which is different from

How do you input commandline argument in IntelliJ IDEA?

The point of this question is, run with the redirct symbol

<

So in command line I can do this

java -cp /classpath MyClass < data.txt

which works good.

But I followed official help document of Intellij and tried to put redirect symbol < in argument.

enter image description here

Intellij threw an

Exception in thread "main" java.lang.IllegalArgumentException.

And I didn't find any illustration about using redirect symbol < with arguments in official help document.

Community
  • 1
  • 1
Kyung Lee
  • 925
  • 1
  • 10
  • 21

2 Answers2

2

For the Program Arguments field, put in a path to the file, instead of the redirect symbol.

So if your IntelliJ project main directory is

/home/glenn/Proj_java/Algorithms/Chapter1/BinarySearch

and your file data.txt is in that directory, just put in this:

data.txt

If you had a subdirectory under that named "mystuff" which contained your file, in Program Arguments use the relative path to the file:

mystuff/data.txt
akubot
  • 141
  • 1
  • 8
  • Thanks, I do exactly know how to avoid redirect symbol "<" in your way, but what if I run the program with more than single argument and "<"? For example $java BinarySearch WhiteList.txt < TotalList.txt , You can't avoid using "<" anymore now. – Kyung Lee Sep 09 '16 at 02:37
  • 1
    In IntelliJ you can pass multiple Program Arguments if you want. So in this case you might try passing this `WhiteList.txt TotalList.txt` Then in your Java code do something like this inside main() to see the filenames passed as Program Arguments: ` for (int i = 0; i < args.length; i++) { System.out.format("arg %d: %s\n", i, args[i]); }; ` You can grab the first filename with args[0] and the second with args[1]. Then in your Java code you can open and read from those files if you want. – akubot Sep 14 '16 at 00:34
1

IntelliJ does not support redirect symbol for now. It's really painful~!

As a compromise, you could try:

FileInputStream fis = new FileInputStream("E:\\GDUT\\Dropbox\\Alg4\\test_data\\eval.txt");
System.setIn(fis);

https://youtrack.jetbrains.com/issue/CPP-3153#tab=Comments

guodong hu
  • 11
  • 1