Answer:

Sure, because output.txt is a text file. Once it has been created it is a text file like any other.

Redirection is an OS Feature

File redirection is a feature of the operating system's command line interface, not a feature of Java. File redirection can be used with any program that writes to the monitor. For example, the DOS command DIR writes a summary of the files in a directory to the monitor:

C:\temp>dir
 Volume in drive C is DISK4_VOL1
 Volume Serial Number is 1C25-5670

 Directory of C:\temp

01/09/2006  07:29p      <DIR>          .
01/09/2006  07:29p      <DIR>          ..
01/09/2006  07:29p                 115 Hello.java
               1 File(s)            115 bytes
               2 Dir(s)  30,987,882,496 bytes free
C:\temp>

You can send the same characters to a file by doing this:

C:\temp>dir > dirlist.txt

You can type out the contents of the new file by doing this:

C:\temp>type dirlist.txt

The same characters as the first DIR command wrote will be written out. Similar commands work for Unix or for Max OS X.

QUESTION 9:

If there already is a file named stuff.txt, what happens if you do:

C:\temp>java myProgram > stuff.txt