zoukankan      html  css  js  c++  java
  • 合并文件(序列流)

    public class Demo3 {


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

    }

    public static void testMerge() 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");

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

    /*//3.用集合存输入流
    ArrayList<FileInputStream> list = new ArrayList<FileInputStream>();
    list.add(inputStream1);
    list.add(inputStream2);

    //4.边读边写
    byte[] b = new byte[1024];
    int length = 0;
    for(int i = 0;i<list.size();i++){
    while((length = list.get(i).read(b)) !=-1){
    //写数据
    outputStream.write(b,0,length);
    }
    }
    //5.关闭
    outputStream.close();
    inputStream1.close();
    inputStream2.close();*/



    //3.建立一个序列流
    SequenceInputStream serInputStream = new SequenceInputStream(inputStream1,inputStream2);
    byte[] b = new byte[1024];

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

    }

  • 相关阅读:
    Hadoop 0.23.1 Release Notes
    maven编译参数
    Hadoop快速入门
    HTML Parser HTML Parser
    EasyHadoop v1.0
    Hudson+Maven+SVN 快速搭建持续集成环境
    对技术要有足够的尊重和敬畏
    hudson设置
    python之强大的日志模块 竹叶青 的专栏 博客频道 CSDN.NET
    PHP学习之七:错误控制运算符
  • 原文地址:https://www.cnblogs.com/future-zmy/p/6144714.html
Copyright © 2011-2022 走看看