简体   繁体   中英

PDF not opening

I am invoking a pdf by using

Desktop.getDesktop().open(new File(pdffilename));

The pdf is opening fine in my machine in which I have Adobe Acrobat 9 pro installed. But its not opening in another machine which has Adobe Acrobat version 10.1.2 .

When I open the pdf it displays the error message

java.io.IOException: Failed to open file:/C:/Program%20Files%20(x86)/TheatreAudi t/data/AE%20wording.pdf. Error message: Unspecified error

  at sun.awt.windows.WDesktopPeer.ShellExecute(WDesktopPeer.java:59) at sun.awt.windows.WDesktopPeer.open(WDesktopPeer.java:36) at java.awt.Desktop.open(Desktop.java:254) at uk.co.healthiq.MainFrame.linkAEActionPerformed(MainFrame.java:259) at uk.co.healthiq.MainFrame$8.actionPerformed(MainFrame.java:214) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) 

Could someone please help me with this. Thanks.

The path seems incorrect. Try introducing a variable for your file first, then check if that file exists:

File pdfFile = new File(pdffilename);
if (!pdfFile.exists()) {
    throw new IOException("...");
}
Desktop.getDesktop().open(pdfFile);

It seems to me you are passing something like "/C:/...". Try removing the first slash, and if that doesn't help try using windows like backslashes (remember you have to quote these in code).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM