Java SequenceInputStream Class

Java SequenceInputStream class is used to read data from multiple streams. It reads data sequentially (one by one).

Java SequenceInputStream Class declaration

public class SequenceInputStream extends InputStream

Constructors of SequenceInputStream class

Method Description
SequenceInputStream(InputStream s1, InputStream s2) creates a new input stream by reading the data of two input stream in order, first s1 and then s2.
SequenceInputStream(Enumeration e) creates a new input stream by reading the data of an enumeration whose type is InputStream.

Methods of SequenceInputStream class

Method Description
int read() It is used to read the next byte of data from the input stream.
int read(byte[] ary, int off, int len) It is used to read len bytes of data from the input stream into the array of bytes.
int available() It is used to return the maximum number of byte that can be read from an input stream.
void close() It is used to close the input stream.

Java SequenceInputStream Example

Flash Soon


Output:


Example that reads the data from two files and writes into another file

Flash Soon


Output:


SequenceInputStream example that reads data using enumeration

If we need to read the data from more than two files, we need to use Enumeration. Enumeration object can be obtained by calling elements() method of the Vector class. Let's see the simple example where we are reading the data from 4 files: a.txt, b.txt, c.txt and d.txt.

Flash Soon


Output:



Advertisement

© Sapster 2017