public Process exec(String command) throws IOException
和
public Process exec(String cmdarray[]) throws IOException
其实是等价的,最终都会调用
public Process exec(String[] cmdarray, String[] envp, File dir) throws IOException
因为如下代码:
public Process exec(String command, String[] envp, File dir)
throws IOException {
if (command.length() == 0)
throw new IllegalArgumentException("Empty command");
StringTokenizer st = new StringTokenizer(command);
String[] cmdarray = new String[st.countTokens()];
for (int i = 0; st.hasMoreTokens(); i++)
cmdarray[i] = st.nextToken();
return exec(cmdarray, envp, dir);
}
这里最终是:return exec(cmdarray, envp, dir);
本文详细解析了 Java 中的 Process exec 方法的不同形式及其等价性,包括如何将字符串命令转换为字符串数组并执行。
1494

被折叠的 条评论
为什么被折叠?



