IO流 合并流
package com.yyq; /* * 功能流 (合并流) * SequenceInputStream 表示其他输入流的逻辑串联,他从输入流的有序集合开始, * 并从第一个输入流开始读取,直到文件末尾。 * 把三个文件的数据变成一个文件 * * */ import java.io.*; import java.util.Enumeration; import java.util.Vector; public class SequenceInputStreamDemo { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub Vector<FileInputStream> v = new Vector(); v.add(new FileInputStream("1.a")); v.add(new FileInputStream("2.a")); v.add(new FileInputStream("3.a")); Enumeration<FileInputStream> en = v.elements(); SequenceInputStream sis = new SequenceInputStream(en); PrintWriter pw = new PrintWriter(new FileWriter("6.txt")); byte[] buf = new byte[1024]; int num = 0; while((num = sis.read(buf))!=-1){ pw.println(new String(buf,0,num)); } pw.close(); sis.close(); } }