Merge streams: Merge two files together.
The main operation is the content.
Defined:
Public class Sequenceinputstreamextends InputStream
Method Summary:
Operation Steps:
1, set up two file InputStream instance objects, respectively, to output the specified two files.
2, set up a file OutputStream instance, which is used to merge and write two files.
2, through the Sequenceinputstream class, the contents of the two files are combined and placed into this class instance stream.
3, read the contents of the Sequenceinputstream instance and put it in a third file.
Example code:
Packageclass set;ImportJava.io.File;ImportJava.io.SequenceInputStream;ImportJava.io.FileInputStream;ImportJava.io.InputStream;ImportJava.io.FileOutputStream;ImportJava.io.OutputStream; Public classsequencedemo{ Public Static voidMain (String args[])throwsException {//all exceptions ThrownInputStream is1 =NULL;//input stream 1InputStream Is2 =NULL;//input stream 1OutputStream OS =NULL;//output StreamSequenceinputstream sis =NULL;//Merging flowsIs1 =NewFileInputStream ("D:" + File.separator + "A.txt") ; Is2=New FileInputStream("D:" + File.separator + "B.txt") ; OS=New FileOutputStream("D:" + File.separator + "Ab.txt") ; SIS=NewSequenceinputstream (IS1,IS2);//instantiating a merge stream inttemp = 0;//Receive content while(Temp=sis.Read ()) {!=-1) {//Loop OutputOs.Write(temp);//Save Content} sis.close (); //Close Merge StreamIs1.close ();//turn off input stream 1 'Is2.close ();//turn off input stream 2Os.close ();//turn off the output stream }};
Operation Result:
The contents of a, B, are incorporated into AB.
Java IO operations: Merging streams