I am trying to open a PDF file from java using the command line argument as
String command = "cmd /c start AcroRd32.exe \"" + dir + "\"";
But i am getting an error when the file will be automatically opened as
"Windows cannot find 'acroRd32.exe'. Please make sure you typed the correct name."
However i am able to open it manually without using the command line/java.
Please help me out.
I strongly recommend that you do it this way instead.
java.io.File file = new java.io.File("c:/some/file.pdf");
java.awt.Desktop.open(file);
If you still want to run "AcroRd32.exe" (or some other "command") use a ProcessBuilder, with something like this -
ProcessBuilder pb = new ProcessBuilder("AcroRd32.exe", dir);
Process p = pb.start();
I am not sure that this is really useful but it works to open pdf file.
String FileName="C:/name.pdf";//Write your complete path here
try {
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + FileName);
} catch (IOException ex) {
Logger.getLogger(ClassName.class.getName()).log(Level.SEVERE, null, ex);
}
String cmds[] = new String[] {"cmd", "/c", "C:\\test.pdf"};
Runtime.getRuntime().exec(cmds);
START C:\temp\My_PDF_File.pdf use this command for opening from command line
other wise use class desktop