陈华江(HuaChiang Chen) 陈泉冰专栏

未老之前携你远行...

BufferedInputStream(缓冲输入流) 示例

//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;
   }
  }
 }
}
阅读更多
个人分类: Java
上一篇ByteArrayOutputStream(字节数组输出流) 示例
下一篇PushbackInputStream(推回输入流) 示例
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭