go to previous page   go to home page   go to next page highlighting

Answer:

Output redirection.

C:\temp>java MultiEcho < input.txt > output.txt

With PowerShell do this:

C:\temp> type input.txt | java MultiEcho > output.txt

Redirecting both Input and Output

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

C:\temp>java MultiEcho < input.txt > output.txt

C:\temp>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 four,
Enter line5:
You typed: and this is the last line.

The order on the command line does not matter:

C:\temp>java MultiEcho > output.txt < input.txt

The above program, used with redirection, does nothing but copy one file to another. There are easier ways to do this. But a more realistic program might process the data in some way before writing it out. Perhaps it could change some words, or encrypt the entire text.

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


QUESTION 7:

(Thought Question: ) Can you use redirection to send output to two disk files at the same time?


go to previous page   go to home page   go to next page