码迷,mamicode.com
首页 > 其他好文 > 详细

回退流 Demo 1

时间:2017-06-05 14:48:55      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:code   int   color   创建   cep   null   inpu   ack   exce   

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

标签:code   int   color   创建   cep   null   inpu   ack   exce   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!