Here is a sample java program showing how to merge all the PDF files contained in a folder as a new merged PDF document and save it to a new file. This program uses Qoppa’s library jPDFProcess. It can easily be adapted to use jPDFAssemble as well.

// create a new PDF document
PDFDocument mergePDF = new PDFDocument();
// define the folder
File folder = new File("C:\\myfolder");
// loop through all files in the folder
for (File file : folder.listFiles()) 
{
 // if it is a PDF file
 if (file.getName().endsWith("pdf")) 
 {
   // load the current PDF file 
   PDFDocument currentPDF = new PDFDocument(new FileInputStream(file), null);
   // append the current PDF file to the new PDF document
   mergePDF.appendDocument(currentPDF);
 }
}
// save the new PDF document to a file
mergePDF.saveDocument(new FileOutputStream(folder.getPath() + "\\mergePDF.pdf"));