可以把如 a.txt b.txt c.txt等多个文件复制到d.txt文件
构造方法:
SequenceInputStream(Enumeration e)
Enumeration是Vector中的一个方法的返回值类型
Enumeration<E> elements()
代码
package cn.idcast2; import java.io.BufferedOutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.SequenceInputStream; import java.util.Enumeration; import java.util.Vector; /* * 需求:把Day1.java、Day102.java、Day103.java复制到d.txt里。 * */ public class SequenceInputStreamdemo { public static void main(String[] args) throws IOException { Vector<InputStream> v = new Vector<InputStream>(); InputStream ips1 = new FileInputStream("Day1.java"); InputStream ips2 = new FileInputStream("Day102.java"); InputStream ips3 = new FileInputStream("Day103.java"); v.add(ips1); v.add(ips2); v.add(ips3); Enumeration<InputStream> en = v.elements(); SequenceInputStream sis = new SequenceInputStream(en); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream("d.txt")); byte[] bys = new byte[1024]; int len = 0; while ((len = sis.read(bys)) != -1) { bos.write(bys, 0, len); } sis.close(); bos.close(); } }
时间: 2024-09-29 14:25:37