- class myLineNumber
- { private Reader r ;
- private int x =1;
- myLineNumber(Reader r){
- this.r = r;
- }
- public String getLine() throws IOException{
- x++;
- StringBuilder sb = new StringBuilder();
- int chr = 0 ;
- while ((chr = r.read())!=-1)
- {
- if (chr =='\r')
- continue ;
- if (chr =='\n')
- return sb.toString();
- else
- sb.append((char)chr);
- }
- if (sb.length()!=0)
- {
- return sb.toString();
- }
- return null;
- }
- public int getNumber(){
-
- return x;
- }
- public void setNumber(int x){
- this.x = x;
- }
- public void close()throws IOException{
- r.close();
- }
- }
复制代码
不知道这个行不 |