by Dinesh Thakur Category: Stream

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.


class SequenceInputStreamExample
     public static void main(String[] args)
        int ch;
          FileInputStream file1 = new  FileInputStream  ("std.dat");
          FileInputStream file2 = new FileInputStream  ("mydata.dat");
          SequenceInputStream fin=new SequenceInputStream(file1,file2);
          catch(IOException e)  { e.printStackTrace(); }

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles