标签:time public trace import except code gen ret fileread
import java.io.BufferedReader;/**
*/
public class Demo {
public static void main(String[] args) {
MyLineNumberReader r = null;
try {
FileReader fw = new FileReader("c:\字符流缓冲区.txt");
r=new MyLineNumberReader(fw);
String buff = null;
while((buff=r.myReadLine())!=null){
System.out.println(r.getMyLineNumber()+":"+buff);
}
} catch (Exception e) {
throw new RuntimeException("读取错误");
}finally {
if(r!=null){
try {
r.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
class MyLineNumberReader extends BufferedReader{
private int myLineNumber;//行号计数器
public MyLineNumberReader(Reader in) {
super(in);
}
public String myReadLine() throws IOException{
myLineNumber++;
return super.readLine();
}
public int getMyLineNumber() {
return myLineNumber;
}
public void setMyLineNumber(int myLineNumber) {
this.myLineNumber = myLineNumber;
}
}
字符流缓冲区的增强类LineNumberReader之装饰模式
标签:time public trace import except code gen ret fileread
原文地址:http://blog.51cto.com/13579086/2064988