zoukankan      html  css  js  c++  java
  • 序列流实例

    //序列流作用:可以将多个流串联到一起
    public class Demo3 {

    public static void main(String[] args) throws IOException {
    testMerge2();

    }

    public static void testMerge2() throws IOException{
    //1.获取文件
    File file1 = new File("C:\B\a.txt");
    File file2 = new File("C:\B\b.txt");
    File file3 = new File("C:\B\c.txt");
    File file4 = new File("C:\B\d.txt");

    //2.创建通道
    FileInputStream inputStream1 = new FileInputStream(file1);
    FileInputStream inputStream2 = new FileInputStream(file2);
    FileInputStream inputStream3 = new FileInputStream(file3);
    FileOutputStream outputStream = new FileOutputStream(file4);

    //3.创建一个Vector集合对象
    Vector<FileInputStream> v = new Vector<FileInputStream>();
    v.add(inputStream1);
    v.add(inputStream2);
    v.add(inputStream3);

    //4.获取迭代器
    Enumeration<FileInputStream> e = v.elements();

    //5.通过序列将三个流串起来
    SequenceInputStream seq = new SequenceInputStream(e);
    byte[] b = new byte[1024];

    //6.读取数据
    int length = 0;
    while ((length = seq.read(b)) != -1) {
    //写入数据
    outputStream.write(b,0,length);
    }
    //7.关闭流
    outputStream.close();
    seq.close();


    }

    }

  • 相关阅读:
    产品生成器模块的问题图片处理
    jQueryinteface效果集合
    aspx页面中文汉字显示为乱码
    实用的正则表达式
    用javascript操作xml
    标注上下标的方法
    1740 博弈
    1028 母函数
    To resolve the problem of sharepoint can not login
    Modify Sharepoint Login UI
  • 原文地址:https://www.cnblogs.com/future-zmy/p/6146112.html
Copyright © 2011-2022 走看看