Print Flow
byte stream Print stream PrintStream
Character Print stream PrintWriter
Characteristics of the print stream:
A: Only the data is written, no data is read. Only the destination can be manipulated and the data source cannot be manipulated. (data can only be written to the file, not from the file)
B: You can manipulate any type of data.
C: Automatically refreshes if automatic refresh is initiated.
D: The stream is able to manipulate the text file directly.
Which stream objects can manipulate text files directly?
FileInputStream
FileOutputStream
FileReader
FileWriter
PrintStream
PrintWriter
Look at the API, the construction method of the check stream object, if there are both file type and string type parameters, generally speaking, you can manipulate the file directly.
Flow if divided by operation:
Basic flow: Is the ability to read and write files directly
Advanced Streaming: Provides some additional functionality on a basic stream basis
Use as a subclass of writer:
1 Public Static voidMain (string[] args)throwsIOException {2 //use as a subclass of writer3PrintWriter PW =NewPrintWriter ("Pw.txt");4 5Pw.write ("Hello");6Pw.write ("World");7Pw.write ("Java");8 9 pw.close ();Ten}
Characteristics of the print stream:
1: You can manipulate any type of data.
Print ()
println ()
2: Start Auto Refresh
PrintWriter pw = new PrintWriter (New FileWriter ("Pw2.txt"), true);
Or should I call the println () method to
This time not only automatically refreshed, but also to achieve the data line-breaking.
Here's println ()
In fact, it is equivalent to:
Bw.write ();
Bw.newline ();
Bw.flush ();
PrintWriter for automatic refresh and line wrapping:
1 Public Static voidMain (string[] args)throwsIOException {2 //Create a Print flow object3PrintWriter PW =NewPrintWriter (NewFileWriter ("Pw2.txt"),true);4 5Pw.println ("Hello");6Pw.println (true);7PW.PRINTLN (100);8 9 pw.close ();Ten}
Print streams for Java 21-12 IO streams