SequenceInputStream 能将两个输入流合并到一起
个别函数说明
上代码
import java.io.*;
public class SequenceDemo
{
public static void main(String[] args)
{
try
{
FileOutputStream out1=new FileOutputStream(new File("F:\\workspace\\JavaPrj\\test1.txt"));
String str=new String("This is the first file!");
out1.write(str.getBytes());
out1.close();
FileOutputStream out2=new FileOutputStream(new File("F:\\workspace\\JavaPrj\\test2.txt"));
str="This is the second file!";
out2.write(str.getBytes());
out2.close();
FileInputStream in1=new FileInputStream(new File("F:\\workspace\\JavaPrj\\test1.txt"));
FileInputStream in2=new FileInputStream(new File("F:\\workspace\\JavaPrj\\test2.txt"));
SequenceInputStream in=new SequenceInputStream(in1,in2);
FileOutputStream out=new FileOutputStream(new File("F:\\workspace\\JavaPrj\\test12.txt"));
int bt;
while((bt=in.read())!=-1)
{
out.write(bt);
}
in1.close();
in2.close();
in.close();
out.close();
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}