Java--io class, character buffer

Source: Internet
Author: User
Tags readline

Character Buffer Stream
writes text to the character output stream, buffering individual characters, providing efficient writes of individual characters, arrays, and strings
BufferedWriter(Writer out) ;
Creates a buffered character output stream that uses the default size output buffer.
BufferedWriter(Writer out, int sz);
Creates a new buffered character output stream that uses a given size output buffer.

//Methods in the parent class writer
void write(char[] cbuf) ;
Writes an array of characters.
abstract void write(char[] cbuf, int off, int len) ;
Writes a portion of a character array. //This method sub-class implements the
 void write(int c) ;
Writes a single character.
 void write(String str) ;
Writes a string.
 void write(String str, int off, int len) ;
Writes a portion of a string.
void newLine()
Writes a line delimiter.

int
Read ()
     & nbsp;     reads a single character.
 int Read (char[] cbuf)
  & nbsp;        reads the characters into the array.
abstract int Read (char[] cbuf, Int off, int l EN)
           reads a character into a portion of an array. //subclass BufferedReader Implementation
 String readLine()
Reads a line of text. Returns null if the end of the stream has been reached


Public static void Main (string[] args) throws IOException { /* BufferedWriter bufferedwriter = new BufferedWriter (New FileWriter ("4.txt")); String str = "Hello, Kunming"; bufferedwriter.write (str); bufferedwriter.newline (); //write a line break directly, regardless of the system platform bufferedwriter.write (str); Bufferedwriter.close (); */
BufferedReader breader = new BufferedReader (New FileReader ("4.txt")); / * char[] cbuf = new Char[4]; Breader.read (CBUF); System.out.println (New String (CBUF)); * ///Hello, Quentin
/ * String readLine; While ((ReadLine = Breader.readline ()) = null) { System.out.println (readLine);                 } breader.close (); */
//Use BufferedReader bufferedwriter copy BufferedReader bufferedreader = new BufferedReader (New FileReader ("11.java")); BufferedWriter bufferedwriter = new BufferedWriter (New FileWriter ("Copy.java")); //Progressive replication string string = null;
While ((string = Bufferedreader.readline ()) = null) {
bufferedwriter.write (string); bufferedwriter.newline ();   //Read a line to write a line will not put the carriage return to write in, all to write their own line                 }
bufferedreader.close (); bufferedwriter.close ();         } }






Java--io class, character 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.