java 通过图片的网络路径将多张图片压缩到保存本地

要将不同文件夹的文件压缩到一个压缩文件里,关键是要将服务器端的图片在不下载到本地的情况下,压缩到本地,我在网上看过很多压缩的工具类,都是要传文件的本地路径,我想直接用网络路径行不行

做了几天做不出来,很急

不要全量更新就是了

不要下载到本地磁盘来操作的话,那你只能在内存中进行操作了

url = new URL(destUrl);

httpUrl = (HttpURLConnection) url.openConnection();

httpUrl.connect();

bis = new BufferedInputStream(httpUrl.getInputStream());

然后你统一在内存中压缩,压缩完毕保存。

但是,不建议这么做,因为如果图片太大或者量太多,内存会吃不消的

大神这是工具类代码片段,我不太懂流,望指教,求代码
public String AddtoZip(List sourcefilelist, String saveZipFilePath) {
if (sourcefilelist == null || sourcefilelist.isEmpty()) {
return null;
}
sourceFile = new File(sourcefilelist.get(0).toString());
if (!sourceFile.isFile()) {
return null;
}
else {
sourceFileName = sourceFile.getName();
this.setZipfileName(sourceFileName.substring(0,sourceFileName.lastIndexOf(".")) + ".zip");
try {
zipFile = new File(saveZipFilePath, this.getZipfileName());
if (zipFile.exists()) {
int i = 1;
while (true) {
zipFile = new File(saveZipFilePath,this.getZipfileName().substring(0, getZipfileName().lastIndexOf(".zip")) + i + ".zip");
if (!zipFile.exists())
break;
i++;
}
}
if (zipFile.exists()) {
zipFile.deleteOnExit();
}
zipFile.createNewFile();
jos = new ZipOutputStream(new FileOutputStream(zipFile));
jos.setLevel(ziplevel);
for (int i = 0; i < sourcefilelist.size(); i++) {

                 Stzip(jos, new File(sourcefilelist.get(i).toString()));
            }
            jos.finish();
        } catch (Exception e) {
            return null;
        }
        if (zipFile != null)
            return zipFile.getPath();
        else {
            return null;
        }
    }
}

private void Stzip(ZipOutputStream jos, File file) throws IOException, FileNotFoundException {
    sourEntry = new ZipEntry(file.getName());
    FileInputStream fin = new FileInputStream(file);
    BufferedInputStream in = new BufferedInputStream(fin);
    jos.putNextEntry(sourEntry);
    int len;
    while ((len = in.read(buf)) >= 0)
        jos.write(buf, 0, len);
    in.close();
    jos.closeEntry();

}
///////////////////////////////////////////////
ExportUtil exportUtil = new ExportUtil();
        List<InputStream> inList = new ArrayList<>();
        InputStream input = null;
        for (int i = 0; i < images.size(); i++) {
            String imgsrc =images.get(i);
            input = ImageUtils.downFilesGetInputStream(imgsrc);
            inList.add(input);
        }
        exportUtil.AddtoZip(inList, filePath);
  • 然后不知道怎么做了

自己封装一个模块吧,输入的是url,出来的是zip或其他包路径

可以到apache官网上下载:java_unrar-0.3.jar包插件,用于文件的压缩和解压处理,网上有好多demo和案例!

你想屁吃呢