获得文件夹下面文件列表,并删除多余的文件

来源:互联网 发布:内存泄露java 编辑:程序博客网 时间:2024/05/16 10:03
 private boolean deleteOneFile(String folderPath,String fileName) {        String filePath=folderPath+"/"+fileName;        File file = new File(filePath);        if (file.isFile() && file.exists()) {            Log.d("tingxiangdelete",filePath);            return file.delete();        }        return false;    }    private void getFileNameList() {        screenShotFileNameList.clear();        screenShotFileNameList.addAll(getFileList(ScreenShot.screenShotFolderPath));        Collections.sort(screenShotFileNameList);    }    private void deleteRedundentFile() {        getFileNameList();//初始化文件夹截屏图片名字列表        while (screenShotFileNameList.size() > MAX_PICTURE_NUMBER) {            ListIterator it = screenShotFileNameList.listIterator();            String firstFile = (String) it.next();            if(deleteOneFile(ScreenShot.screenShotFolderPath,firstFile)) {                it.remove();            }        }    }
0 0
原创粉丝点击