0 Replies - 6558 Views - Last Post: 01 November 2011 - 04:09 AM Rate Topic: -----

#1 parthcool10  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 13-September 09

Problem in merging ppt files using java

Posted 01 November 2011 - 04:09 AM

I want to merge two ppt files using java.
I have used following code. But after execution of a program, the final merged PPT file contains slides from one input file only.But the size of final merged PPT file is summation of both Input ppt file size.

following is the code.
can you me where is the error in it. I have also put output of it. As you can see.
 List inputs = new ArrayList();
            int total = 0;
            String[] fnames = new String[2];
            fnames[0] = "B.ppt";
            fnames[1] = "A.ppt";
            for (int i = 0; i < fnames.length; i++) {
                File file1 = new File(fnames[i]);
                System.out.println("File Length :: "+(i+1)+" " + file1.length());
                FileInputStream fis1 = new FileInputStream(file1);
                inputs.add(i,fis1);
                total += file1.length();
            }

            System.out.println("total length is " + total);
            SequenceInputStream sis = new SequenceInputStream(Collections.enumeration(inputs));
            System.out.println("SequenceInputStream.available() = " + sis.available());
            DataOutputStream dos = new DataOutputStream(new FileOutputStream("Sample.ppt"));
            byte[] merge = new byte[total];
            int soFar = 0,x=0;
            do {

                soFar = sis.read(merge, soFar, total - soFar);
                System.out.println("soFar = "+soFar);
                dos.write(merge, x,soFar);
                x = x + soFar;
                System.out.println("X = "+x);
                System.out.println("read = "+soFar);
                System.out.println("---- LOOP ----");
            } while (x != total);
            dos.close();



Output:
File Length :: 1 776704
File Length :: 2 342016
total length is 1118720
SequenceInputStream.available() = 776704
soFar = 776704
X = 776704
read = 776704
---- LOOP ----
soFar = 342016
X = 1118720
read = 342016
---- LOOP ----


Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1