重写readline方法
来源:互联网 发布:java 导出csv文件 编辑:程序博客网 时间:2024/05/01 03:46
package com.xiaorenwu.iotest;import java.io.FileReader;import java.io.IOException;public class ReadLine1 { //声明一个字符数组当做缓冲区 private char buf[] =new char[1024]; //声明一个字符数组指针用于标记位置 private int pos; //声明一个计数器用于记录字符数组中的元素个数 private int count; //声明一个读入文件流。用于接收读入文件流 private FileReader fr; //构造函数,给变量进行初始化 public ReadLine1(FileReader fr){ this.fr=fr; pos=0; count=0; } //定义myRead() public int myRead() throws IOException{ if(count==0){ count=fr.read(buf); pos=0; //如果数组中没有元素,从源中取出一批元素, //存放在数组中,并用count记录其个数 //并重新初始化指针 } if(count!=-1){ count--; return buf[pos++]; }else{ return -1; } } public String myReadLine() throws IOException{ StringBuilder sb=new StringBuilder(); int ch=0; while((ch=myRead())!=-1){ if((char)ch=='\r'){ continue; } if((char)ch=='\n'){ break; } sb.append(ch); } return sb.toString(); }}
阅读全文
0 0
- 重写readline方法
- readLine()方法
- BufferReader中的readLine()方法
- python readline()方法详解
- BufferedReader readLine()是阻塞方法
- 自定义BuufferedReader中的readLine方法。
- DataInputStream的过期方法readLine()
- Java BufferedReader readLine方法i
- readline()
- readLine
- readLine
- readline
- 方法重写
- 方法重写
- 方法重写
- 方法重写
- 方法重写
- 方法重写
- 动态迭代一例
- Android 两行代码实现沉浸式
- shell的编程结构体
- Flink on Yarn(HA配置)
- Pandas学习(二)——双色球开奖数据分析
- 重写readline方法
- Zookeeper的集群配置和Java测试程序
- 半年总结
- bzoj 2818 Gcd
- 剑指offer_数组---数组中重复的数字
- Leaflet调用谷歌地图、天地图、智图地图、高德题图一键搞定
- 1042:计算一个整数N的阶乘
- constraint用法总结
- Source Insight安装包以及破解文件