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