Java IO stream two-character stream input and output buffers

Source: Internet
Author: User

/* characters written to buffer stream buffers appear in order to improve the operational efficiency of the stream. So before you create a buffer, you must have an existing stream object. Writer corresponds to Bufferedwriterreader bufferedreader the buffer provides a line break method, NewLine (); */import Java.io.*;class Bufferedwriterdemo {public static void main (string[] args) throws Ioexception{filewriter fw=new FileWriter ("d:/myfile/ Mycode/3.txt ");//Create a character to write to the stream object. BufferedWriter bw=new BufferedWriter (FW);//In order to improve the character writing flow efficiency, the buffer technology is added. Simply pass the stream object that needs to be improved as an argument to the constructor of the buffer. Bw.write ("ABCDE"); Bw.newline ();//newline character bw.write ("HelloWorld"), Bw.flush ();//NOTE: If the buffer is used, the Bw.close () will be refreshed ();//Closing the buffer is closing the stream resource , so there is no need for fw.close ();}}
/* character read stream buffer. This buffer provides a way to read one line at a time, facilitating the acquisition of text data. The method is ReadLine () when NULL is returned to indicate that the end of the file is read. */import java.io.*;class Bufferedreaderdemo {public static void main (string[] args) throws Ioexception{filereader Fr=new FileReader ("D:/myfile/mycode/3.txt"); BufferedReader br=new BufferedReader (FR); String Line=null;while ((Line=br.readline ())!=null) {System.out.println (line);}}}



Java IO stream two-character stream input and output buffers

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.