Java 12-5 character stream with buffer

Source: Internet
Author: User

Character stream for efficient reading and writing, also provides the corresponding characters buffer stream.

Character Buffer stream:
A, BufferedWriter: Character buffered output stream
B, BufferedReader: character buffered input stream

A, BufferedWriter: Character buffered output stream
Writes text to the character output stream, buffering individual characters, providing efficient writes of individual characters, arrays, and strings.
You can specify the size of the buffer, or accept the default size. In most cases, the default value is large enough.

1         //character buffered input stream 2         bufferedwriter bw = new BufferedWriter (New outputstreamwriter (3                 new FileOutputStream (" A.txt ")));
* //Simplified version:
* bufferedwriter BW = new BufferedWriter (New FileWriter ("A.txt")); 4 bw.write ("hehe"), 5 bw.write ("This is a"), 6 bw.write ("cold joke"); 7 8 bw.close ( ), ten}

B, BufferedReader: character buffered input stream
Reads text from the character input stream, buffering individual characters, enabling efficient reading of characters, arrays, and rows.
You can specify the size of the buffer, or you can use the default size. In most cases, the default value is large enough.

1         //character buffer input stream2BufferedReader br =NewBufferedReader (NewFileReader ("A.txt"));3         intLen = 0;4         Char[] ch =New Char[1024];5          while(len = br.read (ch))! =-1){6System.out.println (NewString (Ch,0,len));//Print the contents of the a.txt in a string way7         }8         9         Ten         //Freeing Resources OneBr.close ();

Java 12-5 character stream with buffer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.