zoukankan      html  css  js  c++  java
  • 回退流 Demo 1

    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);
                    }
            }
            
                    
        }
  • 相关阅读:
    PHP函数
    git (1)
    JavaScript(4)
    javascript-DOM(3)
    JavaScript-DOM(2)
    [转]分布式架构知识体系
    Mysql中查看每个IP的连接数
    Git常用命令备忘录
    windows下用vscode写C++
    sudo cd为什么不能够执行?
  • 原文地址:https://www.cnblogs.com/yuanyuan2017/p/6944818.html
Copyright © 2011-2022 走看看