是的,我已经知道这个问题是重复的,但在这里请允许我。其他问题都没有回答这个问题。
这是我的代码:
package pc.setup;
import java.io.IOException;
public class DirectoryCreator {
public static void setupDirectories() throws IOException {
Runtime.getRuntime().exec("cd\\");
}
}
这是我得到的错误:
Exception in thread "main" java.io.IOException: Cannot run program "cd\": 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 pc.setup.DirectoryCreator.setupDirectories(DirectoryCreator.java:7)
at pc.load.PieClickerRunner.main(PieClickerRunner.java:9)
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)
... 6 more
谢谢大家的回答。但是,它们是罗word的,因此在此答案中,我将尝试对其进行总结。
调用时Runtime.getRuntime.exec()
,必须指定正在使用的shell(仅在Windows上)。所以,你会说Runtime.getRuntime.exec("command here", "cmd.exe")
。您可能知道,CMD是现代Windows操作系统的Windows命令外壳。
再次感谢您的回答。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句