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(); } }
时间: 2024-10-13 10:15:11