If you want to read data from two files you can use
the second constructor of SequenceInputStream class, whereas if you want to
read data from multiple files you can use first constructor.

First constructor takes Enumeration as argument. To
do so, we can use Vector class.

Example of SequenceInputStream class using first constructor.

import
java.io.*;

import
java.util.*;

class
SequenceReading

{

public static void main(String[]
args)

{

try

{

FileInputStream fis1=new
FileInputStream("File1.txt");

FileInputStream fis2=new
FileInputStream("File2.txt");

FileInputStream fis3=new
FileInputStream("File3.txt");

FileInputStream fis4=new
FileInputStream("File4.txt");

FileOutputStream fos=new
FileOutputStream("Resultant.txt");

Vector v=new Vector();

v.add(fis1);

v.add(fis2);

v.add(fis3);

v.add(fis4);

Enumeration
en=v.elements();

SequenceInputStream
sis=new SequenceInputStream(en);

int data;

while((data=sis.read())!=-1)

{

fos.write(data);

}

}

catch
(FileNotFoundException fnfe)

{

System.out.println("One
or more files not found "+fnfe);

}

catch(IOException ioe)

{

System.out.println("IO
exception occurs "+ioe);

}

}

}

Example of SequenceInputStream class using second constructor.

import
java.io.*;

import
java.util.*;

class
SequenceReading

{

public static void main(String[] args)

{

try

{

FileInputStream fis1=new
FileInputStream("File1.txt");

FileInputStream fis2=new
FileInputStream("File2.txt");

FileOutputStream fos=new
FileOutputStream("Resultant.txt");

SequenceInputStream sis=new SequenceInputStream(fis1,fis2);

int data;

while((data=sis.read())!=-1)

{

fos.write(data);

}

}

catch
(FileNotFoundException fnfe)

{

System.out.println("One
or more files not found "+fnfe);

}

catch(IOException ioe)

{

System.out.println("Unexpected
error occures");

}

}

}

Since
FileInputStream, FileOutputStream classes throws checked exception, handling
of these exceptions are necessary, otherwise compiler will throw an error saying
Unreported exception must be caught
or declared to be thrown.