六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 61|回复: 0

BufferedInputStream(缓冲输入流) 示例

[复制链接]

升级  57%

113

主题

113

主题

113

主题

举人

Rank: 3Rank: 3

积分
371
 楼主| 发表于 2013-1-27 04:47:55 | 显示全部楼层 |阅读模式
//Used buffered input.
import java.io.*;
class BufferedInputStreamDemo{
 public static void main(String[] args) throws IOException{
  String s = "This is a © copyright symbol but this is &copy not.\n";
  byte buf[] = s.getBytes();
  ByteArrayInputStream in = new ByteArrayInputStream(buf);
  BufferedInputStream f = new BufferedInputStream(in);
  int c;
  boolean marked = false;
  while((c=f.read()) !=-1){
   switch(c){
    case '&':
     if(!marked){
      f.mark(32);
      marked = true;
    }else{
     marked = false;
    }
    break;
    case ';':
     if(marked){
      marked = false;
      System.out.print("(c)");
    }else{
     System.out.print((char)c);
    }
    break;
    case ' ':
     if(marked){
      marked = false;
      f.reset();
      System.out.print("&");
    }else{
     System.out.print((char)c);
    }
    break;
    default:
     if(!marked){
      System.out.print((char)c);
    }
    break;
   }
  }
 }
}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表