当我用下面的语句执行unix指令删除文件的时候,因为Temp目录下面包含的文件太多(20000左右),所以实际执行时间很长,但是在程序里根本没执行完这条指令就跳过去了(执行该语句所用时间总是0)。所以在这里请教高手如何强制使该语句执行完毕下面程序再接着走?
...
long startTime = System.currentTimeMillis();
String command="rm -rf Temp/*.*";
Process proc = Runtime.getRuntime().exec(command);
long endTime = System.currentTimeMillis();
long totalTime = (endTime-startTime)/1000;
System.out.println("Take Time:"+totalTime);//总是返回0
if(proc.waitFor()!=0){
System.out.println("Command Execution Failed!");}
...
...
long startTime = System.currentTimeMillis();
String command="rm -rf Temp/*.*";
Process proc = Runtime.getRuntime().exec(command);
long endTime = System.currentTimeMillis();
long totalTime = (endTime-startTime)/1000;
System.out.println("Take Time:"+totalTime);//总是返回0
if(proc.waitFor()!=0){
System.out.println("Command Execution Failed!");}
...
long startTime = System.currentTimeMillis();
String command="./delFile.bin Temp/*.*";
Process proc = Runtime.getRuntime().exec(command);
long endTime = System.currentTimeMillis();
long totalTime = (endTime-startTime)/1000;
System.out.println("Take Time:"+totalTime);//总是返回0
if(proc.waitFor()!=0){
System.out.println("Command Execution Failed!");}
delFile.bin 内容
rm -f $1
echo $1 deleted successfully!delFile.bin属性755
可同样还是出现问题啊!
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.htmlThank you all for help!