zoukankan      html  css  js  c++  java
  • 实现BufferedReader方法

    package privateclass;
    
    import java.io.Closeable;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.concurrent.CountDownLatch;
    
    public class MyBufferedReader {
    
    	private FileReader reader;
    	private int count = 0;
    	private int pos = 0;
    	private char []buf = new char[1024];
    	
    	public MyBufferedReader(FileReader reader) {
    		this.reader = reader;
    	}
    	public int Myread() throws IOException {
    		if(count == 0)
    		{
    			count = reader.read(buf);
    			pos = 0;
    		}
    		if(count < 0)return -1;
    		char ch = buf[pos];
    		pos++;
    		count--;
    		return ch;
    	}
    	public String Myreadline() throws IOException {
    		StringBuilder s = new StringBuilder();
    		int ch = 0;
    		while((ch = Myread()) != -1)
    		{
    			if(ch == '
    ')continue;
    			if(ch == '
    ')return s.toString();
    			s.append((char)ch);
    		}
    		/*
    		 * 在这里是因为怕读不到回车
    		 */
    		if(s.length() != 0)
    		return s.toString();
    		return null;
    	}
    	public void close() throws IOException {
    		reader.close();
    	}
    }
    

      

  • 相关阅读:
    Linux下定时删除指定目下n天前的文件
    日期时间格式化
    sed与awk
    Linux守护进程(init.d和xinetd)
    python-Json模块
    python3 urllib模块
    linux 命令 rsync
    Linux下scp的用法
    代码块重定向
    使用exec
  • 原文地址:https://www.cnblogs.com/WINDZLY/p/11788779.html
Copyright © 2011-2022 走看看