JavaIO - print streams

Print stream may directly operate the input streams and files.

Is not responsible for the data source, data is only responsible purpose 
for the other output streams, add functionality 
not throw IO exception, but may throw other exceptions

PrintStream PrintWriter and the difference between :

● consistent method name, is generally used PrintWriter, more flexibility 

● PrintWriter PrintStream class class implements all the print method 

distinction ● PrintStream PrintWriter in configuration and method, the output destination specified 

● PrintStream constructor method receives: File Object , the path string, bytes output of the OutputStream 

● constructor method receives the PrintWriter: File objects, the string path, the OutputStream output stream of bytes, character output stream Writer

1.PrintStream (byte stream print)

Its printing method print can guarantee manifestations of the same value. Write what it was like, what is the destination

Class common methods:

● PpintStream (File file): File object instantiated by a class PrintStream 
● printStream (OutputStream out): receiving OutputStream object, instantiating class PrintStream
● printf (Locale l, String format , Object args): formatted according to the specified Locale output
● printf (String format, Object args ): according to the local environment formatted output
● Print (
Boolean B): this method is overloaded multiple times, the output of any data
● the println (
Boolean B): this method is overloaded multiple times, after the output data of any line feed

Formatting Output: string using% s, using integer% d, decimals using% f, using characters% c

printf ( "Name:% s; Age:% d; score:% f; Gender:% c", name, age , score, sex);

2.PrintWriter (character print streams)

Character print streams almost has the basic functions of a character output stream, only increased the print function

Guess you like

Origin www.cnblogs.com/Dm920/p/12461657.html