import java.io.*;
class MyBufferedReader
{
private FileReader fr;
MyBufferedReader(FileReader fr)
{
this.fr=fr;
}
public String myReadLine() throws IOException
{
StringBuilder sb=new StringBuilder();
int len=0;
while((len=fr.read())!=-1)
{
if(len=='\r')
continue;
if(len=='\n')
return sb.toString();
sb.append((char)len);
}
return null;
}
public void myClose() throws IOException
{
fr.close();
}
}
class MyBufferedReaderDemo1
{
public static void main(String[] args)
{
FileReader fr=null;
MyBufferedReader mb=null;
try
{
fr=new FileReader("C:\\Users\\pan\\Desktop\\Demo.java");
mb=new MyBufferedReader(fr);
String s=null;
while((s=mb.myReadLine())!=null)
{
System.out.println(s);
}
}
catch (IOException e)
{
System.out.println(e.toString());
}
finally
{
try
{
mb.myClose();
}
catch (IOException e)
{
System.out.println(e.toString());
}
}
}
} |
|