Java Io-file (Buffered stream)

Source: Internet
Author: User
Tags readline


Bufferedwriter:java program------>test.txt

Primary method: void Write (char ch);//write a single character.

void Write (char []cbuf,int off,int len)//writes a portion of the character data.

void Write (String s,int off,int len)//writes a portion of the string.

void NewLine ()//writes a line delimiter.

void Flush ();//refreshes the buffer in the stream. Write the buffered data to the destination file.

void close ();//closes the stream and refreshes it before closing.

 Public classBufferedwriterdemo { Public Static voidMain (string[] args)throwsIOException {FileWriter fw=NewFileWriter ("Buffered.txt");//fw.write ("ok168");//fw.close ();        /*** In order to improve the efficiency of writing, a buffer of character stream is used.         * Creates a buffer object that writes a character to the stream and associates it with the flow object specified to be buffered. */BufferedWriter BUFW=NewBufferedWriter (FW); //writes data to the buffer using a method in the buffer. Bufw.write ("Hello World!"));        Bufw.newline ();        Bufw.newline (); Bufw.write ("!hello World!"); Bufw.write ("!hello World!"); //use the methods in the buffer to flush the data to the destination file. Bufw.flush (); //closes the buffer while closing the FW stream objectBufw.close (); }}

BufferedReader:test.txt------The >java program

Construction method: BufferedReader br = new Bufferreader (Reader in);

Main methods: int read (); Reads a single character.

int read (char[] cbuf,int off,int len);//reads a character into a part of the array. Returns the number of characters read. Reach the tail, return-1.

String ReadLine (); Reads a line of text.

void Close (); Closes the stream. and frees all resources associated with the stream.

1  Public classBufferreaderdemo {2     //d:/test.txt------The >java program3      Public Static voidMain (string[] args)throwsException {4FileReader FR =NewFileReader ("D:/test.txt");5BufferedReader br =NewBufferedReader (FR);6         7 //String str = br.readline ();8 //While (str! = null) {9 //System.out.println (str);Ten //str = br.readline (); One //        } A          -String str= ""; -          while((Str=br.readline ())! =NULL){ the System.out.println (str); -         } -          -          +     } -  +}

Java Io-file (Buffered stream)

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.