JAVA Program to Copy Two Files Sequentially into Third File

JAVA Program to Copy Two Files Sequentially into Third File:

/* COPY TWO FILES SEQUENTIALLY IN THIRD FILE */
import java.io.*;
class filecopy2
{
 public static void main(String args[])
 {
   FileInputStream i1=null;
   FileInputStream i2=null;
   FileOutputStream o=null;


   try
   {
    i1=new FileInputStream("abc.txt");
    i2= new FileInputStream("def.txt");
    o=new FileOutputStream("jpg.txt");
    SequenceInputStream sis= new SequenceInputStream(i1,i2);
    int ch;
    while((ch=sis.read())!=-1)
    {
     o.write((char)ch);
    }
   }
   catch(Exception e){}
   finally
   {
    try
    {
     i1.close();
     i2.close();
     o.close();
    }
    catch(Exception e){}
   }
 }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.