首页 > 编程语言 > 详细

java下io文件合并功能

时间:2015-09-03 20:24:40      阅读:203      评论:0      收藏:0      [点我收藏+]
package cn.stat.p1.file;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.SequenceInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;

public class sequendemo {

    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        /*这个方法可以用,但是过期了
        Vector<FileInputStream> v=new Vector<FileInputStream>();
        v.add(new FileInputStream("D:\\1.txt"));
        v.add(new FileInputStream("D:\\2.txt"));
        v.add(new FileInputStream("D:\\3.txt"));
        
        Enumeration<FileInputStream> en=v.elements();
        */
        
        ArrayList<FileInputStream> al=new ArrayList<FileInputStream>();
        al.add(new FileInputStream("D:\\1.txt"));
        al.add(new FileInputStream("D:\\2.txt"));
        al.add(new FileInputStream("D:\\3.txt"));
        
        Enumeration<FileInputStream> en=Collections.enumeration(al);
        SequenceInputStream sis=new SequenceInputStream(en);
        
        FileOutputStream fos=new FileOutputStream("D:\\4.txt");
        
        byte[] buf=new byte[1024];
        int len=0;
        while((len=sis.read(buf))!=-1)
        {
            fos.write(buf,0,len);
        }
        
        fos.close();
        sis.close();

    }

}

 

java下io文件合并功能

原文:http://www.cnblogs.com/zywf/p/4780615.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!