I want to know which one is faster. Sequence input stream or file input stream. Here is my sample program
FileInputStream fileInput = new FileInputStream("C:\\Eclipse\\File Output Stream.txt");
FileInputStream fileInput1=new FileInputStream("C:\\Eclipse\\Buffer Output Stream.txt");
SequenceInputStream sequence=new SequenceInputStream(fileInput,fileInput1);
FileOutputStream outputSequenceStream=new FileOutputStream("C:\\Eclipse\\File OutputSequence Stream.txt");
int i=0;
byte[] b = new byte[10];
long start=System.currentTimeMillis();
//System.out.println(start);
while((i=sequence.read())!=-1){
//outputSequenceStream.write(i);
System.out.println(Integer.toBinaryString(i)+" "+i+" "+ (char)i);
}
System.out.println(System.currentTimeMillis()-start);
System.out.println("success");
System.out.println("Reading one file after another using file input");
FileInputStream fileInput2 = new FileInputStream("C:\\Eclipse\\File Output Stream.txt");
FileInputStream fileInput3=new FileInputStream("C:\\Eclipse\\Buffer Output Stream.txt");
start=System.currentTimeMillis();
/* Reading first file */
while((i=fileInput2.read())!=-1){
System.out.println((char)i);
}
/* Reading second file */
while((i=fileInput3.read())!=-1){
System.out.println((char)i);
}
System.out.println(System.currentTimeMillis()-start);
System.out.println("Success");
File input stream gives me less Number than sequence output stream.So does that mean Sequence is slower than file input stream.If so then why do we use sequence stream instead wouldn't it be better to use file input stream?