bufferedwriter: Writes text to the character output stream, buffering individual characters to provide efficient writes of individual characters, arrays, and strings. The Write () method allows you to output the acquired character and then wrap it through newline (). The character stream in BufferedWriter must be brushed out by calling the Flush method. and BufferedWriter can only operate on character streams. If you want to operate on a byte stream, use Bufferedinputstream.
printwriter: Prints the formatted representation of the object to the text output stream (prints formatted representations of objects to a text-output stream). The advantage of PrintWriter relative to BufferedWriter is that if PrintWriter is enabled for automatic refresh, then when PrintWriter invokes the PRINTLN,PRINLF or Format method, The data in the output stream is automatically refreshed. PrintWriter can not only receive character streams, but also can receive byte streams.
socket programming, as far as possible with PrintWriter to replace BufferedWriter, the following is the advantages of PrintWriter:
1. PrintWriter's print and println methods can accept parameters of any type, while the write method of BufferedWriter can only accept characters, array of characters, and strings;
2. PrintWriter's Println method automatically adds line wrapping, BufferedWriter needs to display the calling newline method;
3. The PrintWriter method does not throw the exception, if concerns the exception, needs to call the CheckError method to see whether has the unusual occurrence;
4. PrintWriter construction method can specify parameters, realize automatic refresh cache (AutoFlush);
5. The PrintWriter method is more widely constructed.
-------------------------------------------------------------------
Summary:
When you use the ReadLine method in BufferedReader to receive a character stream in BufferedWriter, the entire line of characters is returned because ReadLine is reading to a newline character. So the BufferedWriter method after entering a paragraph of characters to use the newline method to do a newline operation, and then the character stream brush out. and PrintWriter because the automatic refresh can be turned on, and the Println method in which it takes the line-wrapping operation. So code is easier to implement than BufferedWriter.
PrintWriter and BufferedWriter are inherited java.io.Writer, so many functions are the same. However, PrintWriter provides a println () method to write line breaks for different platforms, and BufferedWriter can set any buffer size. OutputStream can be passed directly to PrintWriter (BufferedWriter cannot receive), such as:
PrintWriter out = new PrintWriter (new Bufferedoutputstream) (New
FileOutputStream ("Foo.out"));
or use OutputStreamWriter to convert OutputStream to Wrtier. Then you can use the BufferedWriter. The JDK API is clearly written in documents.