我尝试使用语句打开 pdf 文件
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+ "Sample.pdf");
。
但我的系统中尚未安装 pdf
阅读器。所以当我执行这个程序时什么也没有显示。没有异常(exception)。如果系统中未安装 Pdf 阅读器,任何想法都会出现异常。如果已安装 Pdf
阅读器,则该程序可以完美运行。
最佳答案
编辑
因为我之前的解决方案不起作用。这是另一个肯定适合您的方法:
try
{
File file = new File("Sample.pdf");
java.awt.Desktop.getDeskTop().open(file);
System.out.println("File opened successfully");
}catch(Exception ex)
{
System.out.println("Error occurred: "+ex);
}
关于java - 如何检查 PDF 阅读器是否安装了 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15630903/