1

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.

Maroun
  • 94,125
  • 30
  • 188
  • 241
alenlee
  • 61
  • 8

2 Answers2

2

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);
}
Vishal K
  • 12,976
  • 2
  • 27
  • 38
0

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);

read/write to Windows Registry using Java

Community
  • 1
  • 1
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • I have included jna jar.but i cant find Advapi32Util jar file.I have tried windows 7 with 64 bit.is there any other jar needed? – Ami Apr 19 '13 at 10:17