3

I have a Java file that I run in the command line like like this:

Java program_file_name<input.txt>output.txt

The Scanner class in the Java file takes in a text file as input and I want it to produce a text file as output, pretty standard stuff.

I looked at the following page: How do you input commandline argument in IntelliJ IDEA?

and tried putting

<input.txt>output.txt

into the program arguments field in run/debug configurations. The output doesn't seem to be showing in the output.txt, it works fine in command line, what am I doing wrong?

Community
  • 1
  • 1
SonicProtein
  • 840
  • 1
  • 11
  • 28

1 Answers1

2

The problem is that what you do in command line is executing shell command which redirects input and output from/to a file. On the other hand java run/debug does not execute shell command but runs selected class with passed arguments. And what you do is that you pass it single argument <input.txt>output.txt. But it does not redirect anything.

What you can do is to modify your class that it accepts arguments - files to read / or write to. I have found one IntelliJ plugin that adds new debug configuration where it is possible to specify file to redirect input. But it is only one half of your request.

Leos Literak
  • 8,805
  • 19
  • 81
  • 156