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