美文网首页
检验本地图片是否已经存在

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

作者: 墨色尘埃 | 来源:发表于2018-08-07 12:32 被阅读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;

    }
















相关文章

网友评论

      本文标题:检验本地图片是否已经存在

      本文链接:https://www.haomeiwen.com/subject/ahcovftx.html