File newFile=new File("mergedFile.pdf");
newFile.createNewFile();
System.out.println(newFile.toURL());
File oldFile1=new File("file1.pdf");
File oldFile2=new File("file2.pdf");
System.out.println(oldFile1.isFile());
System.out.println(oldFile2.isFile());
FileInputStream fin1=new FileInputStream(oldFile1);
FileInputStream fin2=new FileInputStream(oldFile2);
FileOutputStream fout=new FileOutputStream(newFile);
byte[] byteData1=new byte[fin1.available()];
fin1.read(byteData1);
byte[] byteData2=new byte[fin2.available()];
fin2.read(byteData2);
int len=byteData1.length+byteData2.length;
byte[] byteData=new byte[len];
int j=0;
for(int i=0;i<len;i++)
{
if(i<byteData1.length)
{
byteData[i]=byteData1[i];
}
else
{
byteData[i]=byteData2[j];
j++;
}
}
fout.write(byteData);
fin1.close();
fin2.close();
fout.close();
Only the contents of file2.pdf is stored in mergedFile.pdf.What's is wrong with this way of merging the pdf?The byte contents of the file1.pdf and file2.pdf is stored in mergedFile.pdf .