Patricia Silva Patricia Silva - 4 months ago 8
Java Question

Dragon book compiler input

I'm executing the "Dragon book" front-end compiler, which expects a file input using

java main.Main < fileInput.txt

My question is: when I run args.length, the returned value is 0. Isn't fileInput.txt considered an argument? How could I catch it on code?

jso jso

No, you are not passing an argument to the program. Instead you are writing to standard input of the executed program (the content of fileInput.txt can be accessed via

Just in case, example reading:

Scanner scanner = new Scanner(;
while(scanner.hasNextLine()) { 

Edit: Found a similar question now, see: Reading in from - Java ;-)