SequenceInputStream example

SequenceInputStream is used to combine multiple input streams, and creates single SequenceInputStream. And reading from this SequenceInputStream reads the input streams one after another.
Below is simple example showing how to use SequenceInputStream

import java.io.*;
class SequenceInputStreamDemo{
  public static void main(String args[]) throws Exception{

     FileInputStream fin1=new FileInputStream("f1.txt");
     FileInputStream fin2=new FileInputStream("f2.txt");
     FileInputStream fin4=new FileInputStream("f3.txt");

     FileOutputStream fout=new FileOutputStream("f4.txt");

     SequenceInputStream sis=new SequenceInputStream(fin1,fin2);

     SequenceInputStream sis1 = new SequenceInputStream(sis,fin4);

     int i;
     while((i=sis1.read())!=-1)
     {
        fout.write(i);
     }
     sis.close();
     fout.close();
     fin1.close();
     fin2.close();
  }
}

3 thoughts on “SequenceInputStream example”

Leave a Reply