Redirection of input causes the file filename to be opened for reading, and the information stored in this file will be read by the console.readLine() method (or by console.nextLine() if you use the class Scanner for input). The general format for redirection of input is
Redirection of input causes the file filename to be opened for writing. Now the System.out.print and System.out.println methods will produce the output not to the screen, but to the file filename. The general format for redirection of output is
If the file filename exists, it will be overwritten. However, if the instruction
will be used instead, then the new output will be appended to the file filename (if it exists).
One can combine both forms of the input/output redirection. Thus, the instruction
causes reading the input from file filename1 and writing the output to file filename2. In particular, the instruction
will open file filename for input and output.