import java.io.*;
public class Demo
{
public static void main(String[] args) throws IOException
{
BufferedWriter bfw = new BufferedWriter(new FileWriter("b.txt"));
bfw.write("sdasdaad\r\n");
bfw.write("1");
bfw.close();
myreadline bfr = new myreadline(new FileReader("b.txt"));
String s = null;
while((s = bfr.method()) != null)
{
sop(s);
}
bfr.myclose();
}
public static void sop(Object obj)
{
System.out.println(obj);
}
}
class myreadline extends Reader
{
private FileReader r ;
myreadline(FileReader r)
{
this.r = r;
}
public String method() throws IOException
{
StringBuilder sb = new StringBuilder();
int ch =0;
while((ch = r.read()) != -1)
{
if( ch == '\r')
continue;
if(ch == '\n')
return sb.toString();
else
sb.append((char)ch);
}
return null;
}
public void myclose()throws IOException
{
r.close();
}
public void close()throws IOException
{
r.close();
}
public int read(char[] c , int a , int b) throws IOException
{
return r.read(c, a , b);
}
}
为什么只能读取一行呢???