我想断开我的电脑与互联网的连接,而我能想到的最佳方式是从cmd运行ipconfig/release。要做到这一点,我做了Java Runtime.getRuntime()。exec(“ipconfig/release”);返回错误?
Process result = Runtime.getRuntime().exec("ipconfig/release");
这不过抛出一个错误,
java.io.IOException: Cannot run program "ipconfig/release": 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 threadio.run(checkmac.java:141)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find th
e file specified
这我不知道是什么意思。
任何想法我做错了什么?任何更好的选择从路由器断开?
不应该是'ipconfig/release'(注意空间),一般来说,通常使用'ProcessBuilder'并将每个命令和参数分隔为自己的参数'new ProcessBuilder(“ipconfig”, “/ release”);' – MadProgrammer 2015-03-25 05:32:38
@MadProgrammer如果你在Windows上,请从命令行尝试'ipconfig/release' – 2015-03-25 05:33:44
Windows命令行具有错误兼容的行为,可以在斜杠上分割令牌。 'exec'也是一样的, – chrylis 2015-03-25 05:35:31