Java I/O系统之Reader
来源:互联网 发布:韩都衣舍淘宝 编辑:程序博客网 时间:2024/09/21 06:38
1.Reader类型
继承自Reader的流都是用于向程序中输入数据,且数据的单位为字符(16bit);下图中深色为节点流,浅色的为处理流。
2.Reader的基本方法
1) 读取一个字符并以整数形式返回(0~255),如果返回-1已到输入流的末尾。
- int read() throws IOException
2) 读取一系列字符并存储到一个数组buffer,返回实际读取的字符数,如果读取前已到输入流的末尾返回-1
- int read(char[] cbuf) throws IOException
3) 读取length个字符,并存储到一个数组buffer,从length位置开始返回实际读取的字符数,如果读取前输入流的末尾返回-1.
- int read(char[] cbuf, int offset, int length) throws IOException
4) 关闭流释放内存资源
- void close() throws IOException
5) 跳过n个字符不读,返回实际跳过的字节数
- long skip(long n) throws IOException
3.Reader例子
- package com.owen.io;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- /**
- * 读取文件 FileReader
- * @author OwenWilliam 2016-7-19
- * @since
- * @version v1.0.0
- *
- */
- public class TestFileReader
- {
- public static void main(String[] args)
- {
- FileReader fr = null;
- int c = 0;
- try
- {
- fr = new FileReader("E:/workspace/Java/IO/src/com/owen/io/TestFileReader.java");
- int ln = 0;
- while ((c = fr.read()) != -1)
- {
- //char ch = (char) fr.read();
- System.out.print((char) c);
- /*if (++ln >= 100)
- {
- System.out.println();
- ln = 0;
- }*/
- }
- } catch (FileNotFoundException e)
- {
- System.out.println("文件找不到");
- }catch (IOException e)
- {
- System.out.println("文件读取错误");
- }
- }
- }
阅读全文
0 0
- Java I/O系统之Reader
- Java I/O系统之Reader
- 说说 Java I/O 系统之 Reader 与 Writer
- Java I/O总结——Reader
- Java I/O总结——Reader
- Java I/O总结——Reader
- Java I/O Reader and Writer
- 说说 Java I/O 系统之标准 I/O
- 《Java编程思想》之I/O系统
- I/O系统之Java学习总结
- Java 基础知识之I/O系统
- Java I/O系统之InputStream
- Java I/O系统之OutputStream
- Java I/O系统之Writer
- Java I/O系统之转换流
- Java I/O系统之转换流
- Java I/O系统之Print 流
- Java I/O系统之Object流
- tomcat添加工程及启动时报错Could not load the Tomcat server....The configuration may be corrupt or incomplete.
- HBase调优
- 数据结构之图一----相关概念总结
- 【OpenCV】访问Mat中每个像素的值
- 20171109
- Java I/O系统之Reader
- sdk_int值对照表
- 数据类型uint16_t,uint32_t,uint64_t输入输出使用方法
- oracle like用法
- Docker启动nexus3
- caffe单步调试
- php发送post请求的三种方法
- 一头扎进springboot之使用Freemarker模板引擎渲染web视图
- Django QuerySet API