Patricia Silva Patricia Silva - 1 year ago 84
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
Answer Source

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 ;-)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download