我无法弄清楚为什么我的文件没有加载到PDDocument对象中。
我的流程如下:
见下面的代码。
public class Main {
public static void main(String[] args) throws IOException {
//open directory
File folder = new File("pdfs");
//Extract Files
File[] files = folder.listFiles();
//print out file names
for (File file:files) {
System.out.println(file.getName());
System.out.println("Can read?: " + file.canRead());
System.out.println("Can write?: " + file.canWrite());
}
//Load PDF
PDDocument firstDocument = new PDDocument();
try {
firstDocument.load(files[0]);
}
finally
{
if (firstDocument != null) {
firstDocument.close();
}
}
System.out.println("Num Pages: " + firstDocument.getNumberOfPages());
输出:
EnterpriseArchitectInvoice.pdf
Can read?: true
Can write?: true
ooad_textbooks_invoice.pdf
Can read?: true
Can write?: true
Num Pages: 0
我可以保证PDF有效。
感谢您的帮助!!!
答案 0 :(得分:0)