首页 > 其他 > 详细

回退流 Demo 1

时间:2017-06-05 14:46:49      阅读:352      评论:0      收藏:0      [点我收藏+]
package pushbackInputStream;

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

/*
 * 回退输入流 :类 PushbackInputStream
 * 
 * 构造方法:
 * PushbackInputStream(InputStream in) 
          创建 PushbackInputStream 并保存其参数(即输入流 in),以供将来使用。
 */
public class PushbackInputStreamDemo {
    public static void main(String[] args) throws Exception {
        //定义一个字符串
        String str = "hello.world.hah.heihei";
        //定义一个内存输入流
        ByteArrayInputStream ba  = new ByteArrayInputStream(str.getBytes());
        //定义一个回退流对象
        PushbackInputStream pd = null;
        pd = new PushbackInputStream(ba);
        System.out.println("读取之后的数据为:");
        int temp = 0;
        while ((temp =pd.read())!=-1){
            if (temp == ‘.‘) {
               pd.unread(temp);
               temp = pd.read();
               System.out.print("(退回"+(char)temp+")");
            
            }
               else {
                    System.out.print((char)temp);
                }
        }
        
                
    }

 

回退流 Demo 1

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

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