合并流的主要功能是将两个文件的内容合并成一个文件。
如果要实现合并流,则必须使用SequenceInputStream类
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.io.SequenceInputStream; //================================================= // File Name : SequenceInputStream_demo //------------------------------------------------------------------------------ // Author : Common //主类 //Function : SequenceInputStream_demo; public class SequenceInputStream_demo { public static void main(String[] args) throws Exception{ // TODO 自动生成的方法存根 InputStream is1 = null; //输入流1 InputStream is2 = null; //输入流2 OutputStream os = null; //输出流 SequenceInputStream sis = null; //合并流 is1 = new FileInputStream("/home/common/software/coding/HelloWord/HelloWord/a.txt"); is2 = new FileInputStream("/home/common/software/coding/HelloWord/HelloWord/b.txt"); os = new FileOutputStream("/home/common/software/coding/HelloWord/HelloWord/ab.txt"); sis = new SequenceInputStream(is1,is2); //实例化合并流 int temp = 0; while((temp = sis.read()) != -1){ os.write(temp); } sis.close(); is1.close(); is2.close(); os.close(); } }