Sequence InputStream in Java

Java SequenceInputStream class is used to read data from multiple streams or we can say SequenceInputStream is used to copy a number of source files to one destination file. Many input streams are concatenated and converted into a single stream and copied at a stretch to the destination file.

SequenceInputStream contains two constructor –

  • SequenceInputStream(file f1, file f2)
  • SequenceInputStream(Enumeration e)


Read Data from Multiple Files in Java

SequenceInputStream(file f1, file f2) :

SequenceInputStream(file f1, file f2) constructor is used to merge two files only. We can’t read more than two files using this.

Let’s understand this with an easy example. In the following program, take any two files existing in the same directory and pass them to two different FileInputStream constructors. The contents of these two source files are displayed at DOS prompt and also copied to a destination file.

The above code will copy the TestFile1 and TestFile2 and paste the content in the destination file TestFile3.

So like this SequenceInoutStream is used to read more than one file.


SequenceInputStream(Enumeration e):

If we need to read the data from more than two files, we need to have this information in the Enumeration object. Enumeration object can get by calling elements method of the Vector class.

i.e put all the InputStream instances into a Vector and pass that Vector to theSequenceInputStream constructor. Here is an example of how passing a Vector to theSequenceInputStream constructor looks :

This is all about SequenceInputStream , We have seen the use of both constructor of theSequenceInputStream. We have seen, How can we read the two files or more than two files using SequenceInoutStream.

Selenium Tutorial:

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

0 Comment

Leave a Reply