Advertisement
SequenceInputStream(InputStream is1, InputStream is2) |
---|
This constructor takes two InputStream objects in the parameters and combine these two input streams into one input stream for reading.
Example-:
|
Methods | Description |
---|---|
available() | This method gives the remaining number of bytes available to read from this input stream. |
read() | This method reads one byte at a time from this input stream. |
read(byte[]) | This method reads a whole byte array at a time from this input stream. |
close() | This method closes this input stream and also frees any resources connected with this input stream. |
//Program to create a SequenceInputStream to combine two streams
import java.io.*;
class A
{
public static void main(String... ar)
{
try
{
FileInputStream fis1= new FileInputStream("D:\\TextBook1.txt");
FileInputStream fis2= new FileInputStream("D:\\TextBook2.txt");
SequenceInputStream sis= new SequenceInputStream(fis1,fis2); //combining the two input streams
int c;
while( (c=sis.read())!=-1)
{
System.out.print((char)c);
}
bos.flush();
fis1.close();
fis2.close();
sis.close();
}
catch(IOException e)
{
System.out.println(e);
}
}
}
Let us learn-Java
Advertisement
//Program to create a SequenceInputStream to combine two streams
import java.io.*;
class A
{
public static void main(String... ar)
{
try
{
FileInputStream fis1= new FileInputStream("D:\\TextBook1.txt");
FileInputStream fis2= new FileInputStream("D:\\TextBook2.txt");
SequenceInputStream sis= new SequenceInputStream(fis1,fis2); //combining the two input streams
FileOutputStream fos= new FileOutputStream("TextBook3.txt");
BufferedOutputStream bos= new BufferedOutputStream(fos);
int c;
while( (c=sis.read())!=-1)
{
System.out.print((char)c);
bos.write(c);
}
bos.flush();
fis1.close();
fis2.close();
sis.close();
bos.close();
fos.close();
}
catch(IOException e)
{
System.out.println(e);
}
}
}
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement