1. Output the output results to a txt file
Step 1: Header file import java.io.FileOutputStream;
import java.io.PrintStream;
It may also be reminded to throw an error, so import java.io.FileNotFoundException;
Step 2:
PrintStream ps = new PrintStream("e:/log.txt"); // Create a print output stream, the output target is: the log.txt file of the E drive
Step 3:
System.setOut(ps);//Assign the created printout stream to the system. That is, the system will output to ps next time
System.out.println("This line will be written to the log.txt file");
2. Re-output the output to the screen
step one
Step 2
Step 3:
PrintStream out = System.out; // First cache the system's default print output stream
System.out.println("This line is relocated to standard output - screen");