import java.util.*;
import java.io.*;
/*
**包装设计模式设计自己的BufferedReader方法,解密其底层
*/
public class MyBufferedReaderDemo
{
public static void main(String args[]) throws Exception{
FileReader reader = new FileReader("q:/1.txt");
MyBufferedReader br = new MyBufferedReader(reader);
StringBuilder sb = new StringBuilder();
String line = null;
while((line=br.myReadLine())!=null){
sb.append(line+"\r\n");
}
System.out.print(sb.toString());
br.myClose();
}
}
class MyBufferedReader
{
private FileReader reader;
private char b[] = new char[1024];
private int count=0;
private int pos = 0;
public MyBufferedReader(FileReader reader){
this.reader = reader;
}
public int myRead() throws Exception{
if(count==0){
count = reader.read(b);
pos = 0;
}
if(count<0){
return -1;
}
int c = b[pos++];
count--;
return c;
}
public String myReadLine() throws Exception{
StringBuilder sb = new StringBuilder();
int ch = 0;
while((ch=myRead())!=-1){
if(ch=='\r'){
continue;
}
if(ch=='\n'){
return sb.toString();
}
sb.append((char)ch);
}
if(sb.length()!=0){
return sb.toString();
}
return null;
}
public void myClose() throws IOException {
reader.close();
}
}
import java.io.*;
/*
**包装设计模式设计自己的BufferedReader方法,解密其底层
*/
public class MyBufferedReaderDemo
{
public static void main(String args[]) throws Exception{
FileReader reader = new FileReader("q:/1.txt");
MyBufferedReader br = new MyBufferedReader(reader);
StringBuilder sb = new StringBuilder();
String line = null;
while((line=br.myReadLine())!=null){
sb.append(line+"\r\n");
}
System.out.print(sb.toString());
br.myClose();
}
}
class MyBufferedReader
{
private FileReader reader;
private char b[] = new char[1024];
private int count=0;
private int pos = 0;
public MyBufferedReader(FileReader reader){
this.reader = reader;
}
public int myRead() throws Exception{
if(count==0){
count = reader.read(b);
pos = 0;
}
if(count<0){
return -1;
}
int c = b[pos++];
count--;
return c;
}
public String myReadLine() throws Exception{
StringBuilder sb = new StringBuilder();
int ch = 0;
while((ch=myRead())!=-1){
if(ch=='\r'){
continue;
}
if(ch=='\n'){
return sb.toString();
}
sb.append((char)ch);
}
if(sb.length()!=0){
return sb.toString();
}
return null;
}
public void myClose() throws IOException {
reader.close();
}
}