1
我想要使用JFileChooser來分割PDF文件,但PdfReader無法讀取文件。 IOException讀取「Publishing Letter.pdf not found as file or resource」。使用文件上傳訪問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文件?我會怎麼做呢?