首页 > 代码库 > java SequenceInputStream
java SequenceInputStream
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();
}
}
}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。