import java.io.*; class MyBufferedReader { private FileReader fr; MyBufferedReader(FileReader fr) { this.fr = fr; } public String myReadLine() throws IOException//一次读一行数据的方法 { StringBuilder sb = new StringBuilder(); int ch = 0; while((ch=fr.read()) != -1) { if(ch=='\r') continue; if(ch=='\n') return sb.toString(); else sb.append((char)ch); } if(sb.length() != 0) return sb.toString(); return null; } public void myClose() throws IOException { fr.close(); } } class MyLineNumberReader extends MyBufferedReader { //private FileReader fr; private int linenumber; MyLineNumberReader(FileReader fr) { super(fr); } public String MyReaderLine() throws IOException { linenumber++; return super.myReadLine(); } public void setlinenumber(int num) { this.linenumber = num; } public int getlinenumber() { return this.linenumber; } } class MyLineNumberReader2 { public static void main(String[] args) throws IOException { FileReader fr = new FileReader("啊啊啊.txt"); MyLineNumberReader lnr = new MyLineNumberReader(fr); lnr.setlinenumber(100); //从100行开始 String line = null; while((line=lnr.MyReaderLine()) != null) { System.out.println(lnr.getlinenumber()+"::::"+line); } } }
java基础入门---- MyLineNumberReader2
最新推荐文章于 2022-03-15 21:19:18 发布