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();
只有file2.pdf的内容存储在mergedFile.pdf中。这种合并pdf的方法有什么问题?file1.pdf和file2.pdf的字节内容存储在mergedFile.pdf中。