by Dinesh Thakur

The SequencelnputStream class allows you to concatenate (or combine) two or more input streams serially and make them appear as if they were a single input stream. Each input stream is read beginning from the first one until end of file (EOF) is reached, where upon it reads from the second one and so on, until end of file is reached on the last of the contained input streams.

In order to create SequencelnputStream, the following two constructors are provided.

SequencelnputStream(IntputStream s1, InputStream s2)

This constructor creates a SequencelnputStream that reads from the InputStream s1 until its EOF is reached, then closes it and switched to reading from InputStream s2 until itsEOF is reached.

SequencelnputStream(Enumeration e)

This constructor creates a SequencelnputStream initialized to the specified enumeration of InputStreams.

Now let us consider a program that uses SequencelnputStream to concatenate two files.

import java.io.*; 

class SequenceInputStreamExample
{
     public static void main(String[] args)
    {
        int ch;
        try
        {
          FileInputStream file1 = new  FileInputStream  ("std.dat");
          FileInputStream file2 = new FileInputStream  ("mydata.dat");
          SequenceInputStream fin=new SequenceInputStream(file1,file2);
          while((ch=fin.read())!=-1)
              System.out.println(ch);
              fin.close();
          }
          catch(IOException e)  { e.printStackTrace(); }
        }
     }