码迷,mamicode.com
首页 > 编程语言 > 详细

java下io文件合并功能

时间:2015-09-03 20:26:32      阅读:201      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!