我想访问一个 pdf 文件,以便使用 JFileChooser 将其拆分,但 PdfReader 无法读取该文件。IOException 读取“Publishing Letter.pdf 未找到作为文件或资源”。
private void butSelectActionPerformed(java.awt.event.ActionEvent evt) {
int returnValue = fileChooserPdf.showOpenDialog(this);
if(returnValue == JFileChooser.APPROVE_OPTION)
{
int n;
String theFile = fileChooserPdf.getSelectedFile().getName();
String theFileInLower = theFile.toLowerCase();
JOptionPane.showMessageDialog(null, "Reading the file " + theFileInLower, "Ok", JOptionPane.INFORMATION_MESSAGE);
try
{
PdfReader reader = new PdfReader(theFileInLower);
n = reader.getNumberOfPages();
System.out.println("there are " + Integer.toString(n) + " number of pages");
}
catch(IOException io)
{
JOptionPane.showMessageDialog(null, io.toString(), "Ok", JOptionPane.ERROR_MESSAGE);
}
}
else
{
JOptionPane.showMessageDialog(null, "An error occured", "Ok", JOptionPane.ERROR_MESSAGE);
}
}
是否可以使用 JfileChooser 访问 pdf 文件以进行拆分?我该怎么做?