打印流的概述
打印流
The ability to add output data makes it easy to print various data value representations.
The print flow is categorized according to the flow:
Never throw an IO exception
L byte print stream printstream
L character Print stream printwriter
L Method:
void print (String str): Outputs any type of data,
void println(String str): Outputs any type of data, automatically writes a line-break operation
L Code Demo:
/*
* Requirements: Write the specified data to the PrintFile.txt file
*
Analysis
* 1, create a stream
* 2, write data
* 3, close the stream
*/
Public class Printwriterdemo {
Public Static void Main (string[] args) throws IOException {
//Create stream, can pass OutputStreamWriter object also can pass path string
PrintWriter out = new PrintWriter (New FileWriter ("PrintFile.txt"));
PrintWriter out = new printwriter ("PrintFile.txt");
2, write Data
for (int i=0; i<5; i++) {
out.println ("HelloWorld");
}
3, close the stream
Out.close ();
}
}
Print flow complete data refresh automatically
The automatic refresh function of file data can be done by constructing method.
L Construction Method:
L Open File Auto- Refresh write function
Public PrintWriter (OutputStream out, boolean autoflush)
Public PrintWriter (Writer out, boolean AutoFlush)
L Code Demo:
/*
Analysis
* 1, create a stream
* 2, write data
*/
Public class PrintWriterDemo2 {
Public Static void Main (string[] args) throws IOException {
Create a Stream
PrintWriter out= New printwriter(new outputstreamwriternew fileoutputstream("d:\\temp\\ Test.txt ",true)," GBK "),true);
↑ Whether to continue writing ↑ Character Set ↑ Whether to flush writes
Write Data
Out.println ("Tom");
Out.print ("Hello");
3, close the stream
Out.close ();
}
}
Java->io Stream _ print stream