try {
Process pro = null;
Runtime rt = Runtime.getRuntime();
for(int i = 0; i < strfl.length; i++){
pro = rt.exec("cmd /c start copy d:\\" + strfl[i] + " d:\\new\\"+strfl[i]");
}
代码如上,如果strfl.length等于100的话,那么将打开100个cmd窗口!吓人哪!要是10000的话那就机器都爆了!
请问这个问题要如何解决?
Process pro = null;
Runtime rt = Runtime.getRuntime();
for(int i = 0; i < strfl.length; i++){
pro = rt.exec("cmd /c start copy d:\\" + strfl[i] + " d:\\new\\"+strfl[i]");
}
代码如上,如果strfl.length等于100的话,那么将打开100个cmd窗口!吓人哪!要是10000的话那就机器都爆了!
请问这个问题要如何解决?
----------------------------循环外执行?是什么意思?
我现在就是要循环执行很多条语句啊。只不过如果能只开一个cmd窗口,或者每次执行后把当前窗口关了的话,这样就可以了。
=======================
就是要解决这个问题。
开不太明白什么意思,把start去掉应该没问题
怎么通过字符串的长度来做为循环条件呢?
不理解!
Process pro = null;
Runtime rt = Runtime.getRuntime();
for (int i = 0; i < strfl.length; i++) {
try {
1--- //pro = rt.exec("cmd /c start "+ strfl[i]);
2--- pro = rt.exec("cmd "+ strfl[i]);
} catch (IOException e) {
e.printStackTrace();
}
}
第一个好用 但是开了两个 doc 窗口
第二个不好用?
怎么在一个窗口执行两个命令 ?
后在关闭doc窗口?
COPY 文件问题,自己书写程序也非常简单。