本帖最后由 范龙波 于 2013-5-14 22:02 编辑
import java.io.*;
class MyLineNumberReader
{
private Reader r;
private int line;
public MyLineNumberReader(Reader r)
{
this.r=r;
}
public void SetLin(int line)
{
this.line=line;
}
public int GetLin()
{
return line;
}
public String MyLineReader()throws IOException
{
StringBuilder sb=new StringBuilder();
int x=0;
while ((x=r.read())!=-1)
{
line++;
if(x=='\r')
continue;
if(x=='\n')
return sb.toString();
else
sb.append((char)x);
}
if(sb.length()!=0)
return sb.toString();
return null;
}
public void close()throws IOException
{
r.close();
}
}
class MyLineNumberReaderDemo
{
public static void main(String[] args)throws IOException
{
FileReader fr=null;
try
{
fr=new FileReader("BufferedDemo.java");
MyLineNumberReader Myline=new MyLineNumberReader(fr);
String sb=null;
while ((sb=Myline.MyLineReader())!=null)
{
System.out.println(Myline.GetLin()+sb); //找不到符号GetLine 我上面已经定义这个方法了怎么在这还找不到呢?
}
}
catch (IOException x)
{
System.out.println( x.toString());
}
finally
{
fr.close();
}
}
}
//麻烦帮 找 一下我这个代码问题出在了哪里???谢谢
|