Java-如何从Java程序打开windows控制台

Java-如何从Java程序打开windows控制台,java,Java,我想打开“程序”start.bat,但我有一个错误: java.lang.Runtime.exec(未知源) 这是我的代码: File file = new File("C:\\Users\\Admin\\Desktop"); try { Runtime r = Runtime.getRuntime(); Process p = r.exec("start.bat /c start command", null, file); } catch (IOException e) {

我想打开“程序”
start.bat,但我有一个错误:

java.lang.Runtime.exec(未知源)

这是我的代码:

File file = new File("C:\\Users\\Admin\\Desktop");

try {
    Runtime r = Runtime.getRuntime();
    Process p = r.exec("start.bat /c start command", null, file);
}
catch (IOException e) {
    e.printStackTrace();
}

cmd/c
添加到命令中。范例

Process p = r.exec("cmd /c start start.bat", null, file);

尝试将
cmd/c
添加到命令中

这里有一个小提示


@亚瑟:是的。您可以使用所需的任何命令替换它。在您的情况下,
start.bat