-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,570
  • 9
  • 52
  • 78

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
  • 250,062
  • 96
  • 490
  • 643