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

Answer:

Yes — but not with files. Input has been text from the keyboard and output has been text to the monitor.


Redirecting Output

The command line interface of most operating systems supports file redirection. This works for Windows operating systems and operating systems based on Unix, including Max OS. A program that sends its output to the monitor can send its output to a file using output redirection.

Say that you have a program named Hello.java that writes "Hello World" to the monitor. Here is how the program usually works:

C:\temp> java Hello
Hello World
C:\temp>

Without making any changes to the program and without recompiling you can do this:

C:\temp> java Hello > output.txt
C:\temp> 

Do this in a subdirectory (folder) where you have read/write permissions. The subdirectory you have already been using for Java programming should work.

Redirection creates the file called output.txt and fills it with the characters that otherwise would go to the monitor. You can pick any name you want for the output file (but do not pick the name of a file already in the subdirectory because the new file will replace the old file). You do not have to end the file name with .txt but doing that is a helpful reminder that file contains text. When the program finishes, the file output.txt remains on the disk. For example:

C:\temp>type output.txt
Hello World
C:\temp> 

The TYPE command of the Windows command shell asks the operating system to type the file out on the monitor. It works with any text file.


QUESTION 8:

Can you use Notepad to edit output.txt?


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