2016-07-24
Character stream related classes: Reading buffer classes
1,bufferedreader
Packagecom.java1995;ImportJava.io.BufferedReader;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;Importjava.io.IOException;ImportJava.io.InputStreamReader; Public classTestbufferedreader { Public Static voidMain (string[] args) {InputStreamReader ISR=NULL; BufferedReader BR=NULL; Try{ISR=NewInputStreamReader (NewFileInputStream ("D:\\workspace\\java_io\\in.txt"), "UTF-8"); BR=NewBufferedReader (ISR, 1000); Br.mark (100); //First, use Read () intc = 0; C=Br.read (); while(c! =-1) {System.out.print (Char) c); C=Br.read (); } //Second, use ReadLine ()System.out.println ("------------------"); Br.reset (); String Str=Br.readline (); while(str! =NULL) {System.out.println (str); STR=Br.readline (); } } Catch(FileNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } finally { Try{isr.close (); Br.close (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } }}
Resources
[1] Java Easy Start Classic tutorial "full version"
Javase Advanced Section 16th read Buffer class BufferedReader