检验本地图片是否已经存在

2018-08-07  本文已影响4人  墨色尘埃
String path = SDCARD_PATH + File.separator + "zhcnapp"+File.separator+"planPic"+File.separator+regPlanId;

    private List<PhotoInfo> checkLocalPhotoExist(String path, List<PhotoInfo> photos) {

        File dir = new File(path);
        if (dir.exists()) {
            String[] fileNames = dir.list();
            if (fileNames.length > 0) {
                List<String> files = Arrays.asList(fileNames);/*目标路径已有的全部文件的文件名*/
                Iterator<PhotoInfo> iterator = photos.iterator();
                while (iterator.hasNext()) {
                    PhotoInfo photo = iterator.next();
                    String id = photo.getPhotoId();
                    if (files.contains(id)) {//表示已经有该文件
                        iterator.remove();
                        localPhotos.add(photo);
                    } else {/*表示原来的文件中有本次未请求的*/
                        File file = new File(path, id);
                        if (file.exists()) {
                            file.delete();
                        }
                    }
                }
            }
        }


        return photos;

    }
















上一篇 下一篇

猜你喜欢

热点阅读