MyBufferedReader
- package cn.lxl.io;
-
- import java.io.FileReader;
- import java.io.IOException;
-
- /**
- * Created by IntelliJ IDEA.
- * User: Administrator
- * Date: 2011-11-14
- * Time: 10:47:55
- * To change this template use File | Settings | File Templates.
- */
- public class MyBufferedReader {
- private FileReader fileReader;
-
- public MyBufferedReader(FileReader fileReader) {
- this.fileReader = fileReader;
- }
-
- public String myReaderLine() throws IOException {
-
- StringBuilder sb = new StringBuilder();
- int ch = 0;
- while ((ch = fileReader.read()) != -1) {
- if (ch == '\r')
- continue;
- if (ch == '
') {
- return sb.toString();
- } else {
- sb.append((char) ch);
- }
- }
- if (sb.length() != 0) {
- return sb.toString();
- }
- return null;
- }
-
- public void myReaderClose() throws IOException {
- fileReader.close();
- }
-
- }
- package cn.lxl.io;
-
- import java.io.FileReader;
-
- /**
- * Created by IntelliJ IDEA.
- * User: Administrator
- * Date: 2011-11-14
- * Time: 10:57:36
- * To change this template use File | Settings | File Templates.
- */
- public class MyBufferReaderTest1{
- public static void main(String[] args) throws Exception{
- FileReader fr=new FileReader("bw.txt");
- MyBufferedReader mbr=new MyBufferedReader(fr);
- String line=null;
- while((line=mbr.myReaderLine())!=null){
- System.out.println(line);
- }
- }
- }