pushbackInputstream

来源:互联网 发布:本机访问虚拟机nginx 编辑:程序博客网 时间:2024/05/16 06:22

public static void main(String[] args) throws Exception {

  String s = "123456789";
  byte b[] = s.getBytes();
  BufferedInputStream bis = new BufferedInputStream(
    new ByteArrayInputStream(b));
  PushbackInputStream pis = new PushbackInputStream(bis);
  int tmp = 1;
  int i = 0;
  while ((tmp = pis.read()) != -1) {
   if (i == 0)
    pis.mark(100);
    
   if (tmp == '3')
    pis.unread('c');

   System.out.print((char) tmp);
   i++;
  }
  pis.close();
 }

打印结果未123c45678

原创粉丝点击