Print Flow ( PrintStream): The print stream can print any type of data, and the print stream will convert the data to a string before printing
PrintStream can accept files and other byte output streams, so the print stream is an enhancement to the normal byte output stream, which defines a lot of overloaded print () and println () to facilitate the output of various types of data.
PrintWriter
PrintStream: is a byte print stream, and the system.out corresponding type is printstream.
Its constructor can receive values of three data types.
1, string path.
The 2,file object.
3,outputstream.
Note : Three ways to print a stream
void print (data type variable)
println (data type variable)
printf (String format, Object ... args)
Data formats can be customized
The difference between the print and println methods is that a line break is not wrapped
The Print method and the Write method are not the same, print provides automatic refresh.
the normal write method needs to call the flush or Close method to see the data.
After JDK1.5, Java extended the PrintStream, adding formatted output, and using the printf () overloaded method to format the output directly. However, when formatting the output, you need to specify the format of the output data type.
PrintWriter: is a character print stream.
The constructor can receive four types of values.
1, string path.
The 2,file object.
You can also specify an encoding table for data of type. That is, the character set.
3,outputstream
4,writer
for data of type 3,4, you can specify automatic refresh.
Note: When this auto-refresh value is True, only three methods can be used: Println,printf,format.
If you want to have both an automatic refresh, you can perform the encoding. How do I wrap a stream object?
New PrintWriter ( new Outputsteamwriter (new FileOutputStream ("A.txt"), "Utf-8"),true);
If you want to improve efficiency. You also use the Print method.
New PrintWriter (new Bufferdwriter (new Outputsteamwriter) (New FileOutputStream ("A.txt") , "Utf-8")),true);
Java Print Stream (PrintStream)