-2

I heard something like this

java myMainClass < myInputFile.txt

will provide a file as input to my Java program.

But how do I access that input?

J0e3gan
  • 8,740
  • 10
  • 53
  • 80

1 Answers1

2

That command is piping the file into STDIN, which in Java you can access as System.in.

For example, if you want to use a Scanner:

Scanner input = new Scanner(System.in);
Thilo
  • 257,207
  • 101
  • 511
  • 656