Q:

PDFBox does not remove first page

I am trying to remove the first page of every PDF document in a folder.
My code:
File folder = new File("//home//linux//Desktop//f");
File[] fileParts = folder.listFiles();
PDDocument document = null;
for (File pdf : fileParts) {
    try {
        document = PDDocument.load(pdf, "");
        if (document.isEncrypted()) {
            document.setAllSecurityToBeRemoved(true);
            System.out.println("decrypted");
        }
        document.removePage(0);
        document.save(pdf.getName());
        document.close();
    } catch (Exception e) {
        System.out.println("error: " + e.getMessage() + "\n" + e);
    }
}

The code does not show any error or problem, but it does not remove the first page. 
Is there something I am missing? 

A:

Change this line
document.save(pdf.getName());

to this:
document.save(pdf.getAbsolutePath());

Reason: your current code saved the PDF in the current directory of your application, not in //home//linux//Desktop//f.

