Dragon Book Compiler Input

I am running an external Dragon book compiler that expects file input using

java main.Main < fileInput.txt

My question is: when I run args.length, the return value is 0. Is fileInput.txt an argument? How can I catch it by code?

+4
source share
2 answers

No, you are not passing an argument to the program. Instead, you write to the standard input of the executable program (access to the contents fileInput.txtcan be obtained through System.in).

Just in case, an example of reading:

Scanner scanner = new Scanner(System.in);
while(scanner.hasNextLine()) { 
    System.out.println(scanner.nextLine());
}

Change . Found a similar question: Reading from System.in - Java ; -)

+1
source

, . - / io.

+1

Source: https://habr.com/ru/post/1620921/


All Articles