<pre name="code" class="java">import java.io.*;
class MyLine
{
private Reader r;
private int lineNumber;
MyLine(Reader r)
{
this.r=r;
}
public void setLineNumber(int lineNumber)
{
this.lineNumber=lineNumber;
}
public int getLineNumber()
{
return lineNumber;
}
public String ReadLine() throws IOException
{
StringBuilder sb=new StringBuilder();
int s=0;
lineNumber++;
while((s=r.read())!=-1)
{
if(s=='\r')
continue;
if(s=='\n')
return sb.toString();
sb.append((char)s);
}
if(sb.length()!=0)
return sb.toString();
return null;
}
public void myClose()throws IOException
{
r.close();
}
}
public class MyLineReader
{
public static void main(String [] args)throws IOException
{
FileReader fr=new FileReader("d:\\Apple_copy.txt");
MyLine my=new MyLine(fr);
String str=null;
while((str=my.ReadLine())!=null)
{
System.out.println(my.getLineNumber()+":"+str);
}
my.myClose();
}
}
IO流行号
最新推荐文章于 2018-08-13 21:43:51 发布