java SequenceInputStream

时间:2014-05-03 16:24:39   收藏:0   阅读:298

SequenceInputStream 能将两个输入流合并到一起

个别函数说明

bubuko.com,布布扣

上代码

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();
		}
		
	}
}
bubuko.com,布布扣

java SequenceInputStream,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!