本帖最后由 张红 于 2012-6-19 13:06 编辑
class MyLineNumberReader {
private Reader r;
private int lineNumber;
MyLineNumberReader(Reader r){
this.r=r;
}
public String myReadLine() throws IOException{
StringBuffer sb=new StringBuffer();
int b=0;
while((b=r.read())!=-1){
if(b=='/r'){
continue;
}
else if(b=='/n'){
lineNumber++;
return addLineNumber(sb.toString());
}
else{
sb.append((char)b);
}
}
if(sb.length()!=0){
return sb.toString();
}
return null;
}
public String addLineNumber(String str){
return lineNumber+":"+str;
}
public void myClose() throws IOException {
r.close();
}
}在Eclipse中运行不出,不明白/r/n这里为什么发生错误
|
|