I Tried to open a pdf file using a statement
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + "Sample.pdf");
.
But I have not installed a pdf
reader in my system. So it when I execute this program nothing is showing. No Exceptions are comming . Any idea getting the exception if the Pdf
reader is not installed in the system. If the Pdf
reader is already installed this program is working perfect.
EDIT
As my previous solution was not working . Here is another one that would sure work for you:
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);
}
For that you have to deal with the register key.
Use JNI to do the trick.
String productName = Advapi32Util.registryGetStringValue(
WinReg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName");
System.out.printf("Product Name: %s\n", productName);
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.