将图片链接转换成图片打成压缩包的工具类(有直接打包, 有分文件夹打包的)

该博客介绍了一个Java工具类,用于将包含图片链接的集合转换为压缩包,支持直接打包和按文件夹打包两种方式。内容详细解析了如何实现这一功能,最终生成的压缩包结构直观易用。
摘要由CSDN通过智能技术生成
public static void processImagesToZip(HttpServletResponse response, List<String> ossList) throws IOException {
		// 将 OSS 图片地址转换成图片文件
		List<File> fileList = new ArrayList<>();
		for (String ossUrl : ossList) {
			try {
				BufferedImage image = ImageIO.read(new URL(ossUrl));
				//

				String fileName = ossUrl.substring(ossUrl.lastIndexOf("/") + 1)+ UUID.randomUUID()+".jpg";
				File file = new File(fileName);
				ImageIO.write(image, "jpg", file);
				fileList.add(file);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		// 打包压缩图片文件
		File zipFile = new File("kouqiang.zip");
		try (ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile))) {
			byte[] buffer = new byte[1024];

			for (File file : fileList) {
				if (file.exists()) {
					ZipEntry zipEntry = new ZipEntry(file.getName());
					zipOut.putNextEntry(zipEntry);

		
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值