设为首页 加入收藏

TOP

二级Java考试辅导教程:4.7字符流的处理[1]
2014-11-17 13:00:37 】 浏览:8159
Tags:二级 Java 考试辅导 教程 4.7 字符 处理

  java中提供了处理以16位的Unicode码表示的字符流的类,即以Reader和Writer 为基类派生出的一系列类。


4.7.1 Reader和Writer


这两个类是抽象类,只是提供了一系列用于字符流处理的接口,不能生成这两个类的实例,只能通过使用由它们派生出来的子类对象来处理字符流。


1.Reader类是处理所有字符流输入类的父类。


  读取字符
  public int read() throws IOException; //读取一个字符,返回值为读取的字符
  public int read(char cbuf[]) throws IOException; /*读取一系列字符到数组cbuf[]中,返回值为实际读取的字符的数量*/
  public abstract int read(char cbuf[],int off,int len) throws IOException;
  /*读取len个字符,从数组cbuf[]的下标off处开始存放,返回值为实际读取的字符数量,该方法必须由子类实现*/来源:www.examda.com


  标记流
  public boolean markSupported(); //判断当前流是否支持做标记
  public void mark(int readAheadLimit) throws IOException;
   //给当前流作标记,最多支持readAheadLimit个字符的回溯。
  public void reset() throws IOException; //将当前流重置到做标记处


  关闭流
  public abstract void close() throws IOException;


  2. Writer类是处理所有字符流输出类的父类。


  向输出流写入字符
  public void write(int c) throws IOException;
  //将整型值c的低16位写入输出流
  public void write(char cbuf[]) throws IOException;
  //将字符数组cbuf[]写入输出流
  public abstract void write(char cbuf[],int off,int len) throws IOException;
  //将字符数组cbuf[]中的从索引为off的位置处开始的len个字符写入输出流
  public void write(String str) throws IOException;
  //将字符串str中的字符写入输出流
  public void write(String str,int off,int len) throws IOException;
  //将字符串str 中从索引off开始处的len个字符写入输出流


  flush( )
  刷空输出流,并输出所有被缓存的字节。


  关闭流
  public abstract void close() throws IOException;


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇二级Java考试辅导教程:4.6过滤流 下一篇二级Java考试辅导教程:4.7字符流..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目