清除目录下的文件 java

    /**
     * clear redundant files
     */
    public static void clearRedundantFiles() {
        String path = "/data/update/";
        File file = new File(path);
        if (!file.exists()) {
            return;
        }

        File fileList[] = file.listFiles();
        for (int i = 0; i < fileList.length; i++) {
            File fileNode = fileList[i];
            if (fileNode.isDirectory()) {
                continue;
            }
            String fileName = fileNode.getName();
            if (fileName.startsWith("meminfo")|| fileName.startsWith("cpuinfo")) {
                Log.info(TAG, "clearRedundantFiles " + path + fileName);
                File fileObj = new File(path + fileName);
                fileObj.delete();
            }
        }
    }

 

posted @ 2022-05-04 16:41  Hala  阅读(75)  评论(0编辑  收藏  举报