如果我想从 Java 应用程序打开记事本,那么它将打开记事本。但如果我尝试打开 Excel,那么它会给我一个例外。
try
{
Runtime.getRuntime().exec("excel");
}
catch (IOException e)
{
e.printStackTrace();
}
以下是例外:
java.io.IOException: Cannot run program "excel": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at OpenNotepad.main(OpenNotepad.java:18)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more
当我开始->运行-> Excel时,它将打开excel。