I have the following code:
try {
Files.copy(srcFile.toPath(), destFile.toPath(), copyOptions);
} catch (IOException exc) {
System.out.println("IOException on copy: " + exc.getMessage());
System.out.println("Files.copy(" + srcFile.toPath() + ", " + destFile.toPath() + ", copyOptions)");
System.out.println(srcFile.toPath() + " readable is " + srcFile.canRead());
}
This fails for certain PDF files. There is something about these particular PDFs that requires admin rights to copy them. (They are readable, the destination folder is writable; I can replicate the UAC challenge if I try to copy in a Command Prompt.)
I would like to elevate permissions as atomically as possible -- not for my entire program. Ideally, I would hit the first such access denied problem, prompt the user if they want me to copy it anyway, in a yes/no/always/never sort of choice dialog.
If someone wishes, I can write a tiny program which does the above Files.copy, and I might be able to supply one of these persnickety PDFs -- though the one I am working with is a customer's so I would have to look elsewhere or go to great trouble (e.g., with PDFbox) to obscure the text.
I realize there is probably info out there about why some PDFs do this, and I will admit I am ignorant in this area, but that is really rather irrelevant to me, unless -- and this would be a big advantage, but I would still need the privilege solution -- I could detect that a particular file has this "you can't copy me" aspect.
Thanks for any help!
Ok, apparently there is nothing magical about these PDF files, they were just created with some restrictive permissions: