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();


    }

    }

  • 相关阅读:
    前端笔记7
    前端笔记6
    列表、行块元素
    我的学习方法(5)
    (读后摘抄)《计算机程序设计语言的发展》_王汝传
    电影《比利·林恩的中场战事》
    关于优化(1)
    Debug技巧(1)
    奇奇怪怪的东西(1)
    我的学习方法(4)
  • 原文地址:https://www.cnblogs.com/future-zmy/p/6146112.html
Copyright © 2011-2022 走看看