Java Fundamentals Hardening IO Stream Note 39: The special function of the character stream buffer stream

Source: Internet
Author: User

1. Special methods for character buffer streams

BufferedWriter:

1  Public void newLine (): depending on the system to determine the line break

BufferedReader:

1  Public String readLine (): reads one row of data at a time

A string containing the contents of the row, with no line terminator, or null if the end of the stream has been reached

2. code example:

1  Packagecn.itcast_05;2 3 ImportJava.io.BufferedReader;4 ImportJava.io.BufferedWriter;5 ImportJava.io.FileReader;6 ImportJava.io.FileWriter;7 Importjava.io.IOException;8 9 /*Ten * Special methods for character buffer streams: One * BufferedWriter: A * public void NewLine (): Based on system to determine line break - * BufferedReader: - * Public String ReadLine (): reads one row of data at a time the * A string containing the contents of the row, with no line terminator, or null if the end of the stream has been reached  -  */ -  Public classBuffereddemo { -      Public Static voidMain (string[] args)throwsIOException { +         //write (); - read (); +     } A  at     Private Static voidRead ()throwsIOException { -         //creating a character buffer input stream object -BufferedReader br =NewBufferedReader (NewFileReader ("Bw2.txt")); -  -         //Public String ReadLine (): reads one row of data at a time -         //String line = Br.readline (); in         //System.out.println (line); -         //Line = Br.readline (); to         //System.out.println (line); +  -         //The final version of the code theString line =NULL; *          while(line = Br.readline ())! =NULL) { $ System.out.println (line);Panax Notoginseng         } -          the         //Freeing Resources + br.close (); A     } the  +     Private Static voidWrite ()throwsIOException { -         //creating a character buffered output stream object $BufferedWriter BW =NewBufferedWriter (NewFileWriter ("Bw2.txt")); $          for(intx = 0; x < 10; X + +) { -Bw.write ("Hello" +x); -             //bw.write ("\ r \ n"); the bw.newline (); - Bw.flush ();Wuyi         } the bw.close (); -     } Wu  -}

Java Fundamentals Hardening IO Stream Note 39: The special function of the character stream buffer 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.