package org.java.io;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.SequenceInputStream;
import java.util.Enumeration;
import java.util.Vector;
public class SequenceInpustStreamTest
{
public static void main(String[] args) throws IOException
{
sequence();
}//管道合并流
public static void sequence() throws IOException{
Vector<InputStream> v=new Vector<InputStream>();
v.add(new FileInputStream(new File("D:\\info\\1.txt")));
v.add(new FileInputStream(new File("D:\\info\\2.txt")));
v.add(new FileInputStream(new File("D:\\info\\3.txt")));
Enumeration<InputStream> ements=v.elements();
InputStream sequenceInputStream=new SequenceInputStream(ements);
OutputStream out=new FileOutputStream(new File("D:\\info\\4.txt"));
int len=0;
byte[] buf=new byte[1024];
while((len=sequenceInputStream.read(buf))!=-1){
out.write(buf, 0, len);
out.flush();
}
sequenceInputStream.close();
out.close();
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.SequenceInputStream;
import java.util.Enumeration;
import java.util.Vector;
public class SequenceInpustStreamTest
{
public static void main(String[] args) throws IOException
{
sequence();
}//管道合并流
public static void sequence() throws IOException{
Vector<InputStream> v=new Vector<InputStream>();
v.add(new FileInputStream(new File("D:\\info\\1.txt")));
v.add(new FileInputStream(new File("D:\\info\\2.txt")));
v.add(new FileInputStream(new File("D:\\info\\3.txt")));
Enumeration<InputStream> ements=v.elements();
InputStream sequenceInputStream=new SequenceInputStream(ements);
OutputStream out=new FileOutputStream(new File("D:\\info\\4.txt"));
int len=0;
byte[] buf=new byte[1024];
while((len=sequenceInputStream.read(buf))!=-1){
out.write(buf, 0, len);
out.flush();
}
sequenceInputStream.close();
out.close();
}
}