大家好,我使用以下代码清空IE缓存,失败
Runtime.getRuntime().exec("cmd /c del /f /s /q \"C:\\Documents and Settings\\Administrator\\Local Settings\\Temporary Internet Files\\Content.IE5\\*.*\"");但问题是:
1、如果将*.*改为具体的一个文件,则可以删除该文件;
2、如果在别的目录下,如F:\aaa\bbb ccc\ddd\*.*,则没有任何问题!
问:如果IE缓存目录下不允许这样清除,那么为何将*.*换成具体文件又是成功删除的?
请指教,谢谢,谢谢~~

解决方案 »

  1.   

    在命令提示符中执行
    del /f /s /q "C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files\Content.IE5\*.*"
    是什么结果?
      

  2.   

    Runtime.exec失败了, 但是有些文件被删除了, 是这样的吗?
      

  3.   


    不好意思,我表达得不清楚,Runtime.exec正常执行,只是文件一个都没少。但是如果换成其他的目录就是完全正常的。难道是Runtime.exec执行的时候,第一次就碰到一个不可删除的文件,然后接下去的事情也就不做了?可是在命令提示符下del可不是这样,它碰到删不了的会继续删下一个。
      

  4.   

    执行del /f /s /q "C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files\Content.IE5\*.*" 能成功,但是在命令行执行cmd /c del /f /s /q "C:\\Documents and Settings\\Administrator\\Local Settings\\Temporary Internet Files\\Content.IE5\\*.*"肯定不能成功。建议:
    Runtime.getRuntime().exec("cmd /c \"del /f /s /q \"C:\\Documents and Settings\\Administrator\\Local Settings\\Temporary Internet Files\\Content.IE5\\*.*\"\"");
      

  5.   

    <HEAD>
        <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
        <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
        <META HTTP-EQUIV="Expires" CONTENT="0">
        </HEAD>
      

  6.   

    Runtime.getRuntime().exec("cmd.exe",
               "/c",
               "del /f /s /q \"C:\\Documents and Settings\\Administrator\\Local Settings\\Temporary Internet Files\\Content.IE5\\*.*\""
     );
    这样行不
      

  7.   

    很感谢楼上几位朋友。6楼的朋友,这样会报异常:
    Runtime.getRuntime().exec("cmd.exe",
               new String[]{"/c"},
               new File("del /f /s /q \"C:\\Documents and Settings\\Administrator\\Local Settings\\Temporary Internet Files\\Content.IE5\\*.*\"")
     );
    8楼的朋友,结果仍是什么都没删去。目前我只能用java代码遍历再使用exec("del /f /s /q 具体文件");一一删除了,但是java代码遍历文件有点慢。
      

  8.   

    del /f /s /q
    改成
    del /f /s /q /a
      

  9.   

    我觉得你可能是没有完全用对,我在我的机器上测试能够通过,请直接使用下面代码试一下:import java.io.IOException;public class Test { public static void main(String[] args) throws IOException {
    String cmd = "cmd /c \"del /f /s /q \"C:\\Documents and Settings\\Administrator\\Local Settings\\Temporary Internet Files\\Content.IE5\\*.*\"\"";
    Runtime runtime = Runtime.getRuntime();
    runtime.exec(cmd);
    }
    }
      

  10.   

    另外可以试试这段代码(用到了commons-io)import java.io.File;
    import java.io.IOException;import org.apache.commons.io.FileUtils;public class Test { public static void main(String[] args) throws IOException {
    String dir = "C:\\Documents and Settings\\Administrator\\Local Settings\\Temporary Internet Files\\Content.IE5\\";
    FileUtils.deleteQuietly(new File(dir));
    }
    }
      

  11.   

    这个倒是确实可以,我原以为速度有点慢,没想到还是可以的。  但是用Runtime那个方法的,看来跟系统有关系,我这里还真不行,一定要指明具体文件才可以。
      

  12.   

    #10的慢是慢在对每个文件都exec, 每次exec当然慢. java文件遍历不慢, 遍历后直接File.delete就可以了. 这是FileUtils的做法.