本文主要是介绍自定义BufferedReader,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
import java.io.FileReader;
import java.io.IOException;class MyBufferedReader {private FileReader r;MyBufferedReader(FileReader r) {this.r = r;}// 按行读public String myReadLine() throws IOException {StringBuilder sb = new StringBuilder();int ch = 0;while ((ch = r.read()) != -1) {if (ch == '\r')continue;if (ch == '\n')return sb.toString();sb.append((char) ch);}if(sb.length()!=0) //将最后一行返回return sb.toString();return null;}//关闭public void myClose() throws IOException {r.close();}
}
这篇关于自定义BufferedReader的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!