Redirecting both Input and Output

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Answer:

C:/users/default/JavaLessons>java MultiEcho < input.txt > output.txt

D:/users/default/JavaLessons>

Redirecting both Input and Output

Input and output redirection can be used simultaneously. Here is an example run of the program:

C:/users/default/JavaLessons>java MultiEcho < input.txt > output.txt

C:/users/default/JavaLessons>type output.txt
Enter line1:
You typed: This is line one,
Enter line2:
You typed: this is line two,
Enter line3:
You typed: this is line three,
Enter line4:
You typed: this is line, uh... four,
Enter line5:
You typed: and this is the last line.

The order on the command line does not matter:

C:/users/default/JavaLessons>java MultiEcho > output.txt < input.txt

You can have only one input file redirected to a program and one output file redirected from a program.

QUESTION 7:

(Review Question: ) How have our Java programs been reading numerical data?