首页 > 其他 > 详细

回退流 Demo2

时间:2017-06-05 14:44:13      阅读:301      评论:0      收藏:0      [点我收藏+]
package pushbackInputStream;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;

/*
 * 自己再写一次
 */
public class PushbackInputStreamDemo2 {
    public static void main(String[] args) throws Exception {
        //定义一个字符串
        String str = "hello.hai.heihei.laiba...";
        //定义一个内存输入流对象
        ByteArrayInputStream bai = new ByteArrayInputStream(str.getBytes());
        //定义一个回退流对象
        PushbackInputStream pbi = new PushbackInputStream(bai);
        System.out.println("读取的数据为:");
        int temp = 0;
        while ((temp = pbi.read())!=-1) {
          if (temp ==‘.‘) {
            pbi.unread(temp);
             temp = pbi.read();
             System.out.print("(回退"+(char)temp+")");
        }
          else {
              System.out.print((char)temp);
        }
            
        }
        
    }

}

 

回退流 Demo2

原文:http://www.cnblogs.com/yuanyuan2017/p/6944828.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!