In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to download Java package". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "Java how to download compressed package" bar!
Package com.golden.crm.web.util;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.IOException;import java.io.InputStream;import java.net.HttpURLConnection;import java.net.URL;import java.util.List;import java.util.zip.ZipEntry;import java.util.zip.ZipOutputStream;/** * download the zip utility class * / public class ZipUtil {private static final Logger logger = LoggerFactory.getLogger (ZipUtil.class) / * generate Zip file * / public static void generateZipFile (HttpServletResponse response, List fileUrl, String fileName) throws IOException {ZipOutputStream zipOut = new ZipOutputStream (response.getOutputStream ()); for (int I = 0; I
< fileUrl.size(); i++) { zipOut.putNextEntry(new ZipEntry(System.currentTimeMillis() + ".jpg")); InputStream stream = this.getInputStreamByUrl(fileUrl.get(i)); if (null == stream) { continue; } int temp = 0; while ((temp = stream.read()) != -1) { zipOut.write(temp); } stream.close(); } zipOut.closeEntry(); zipOut.close(); } /** * 通过url读取图片信息 */ public static InputStream getInputStreamByUrl(String url) { InputStream ins = null; try { URL url_ = new URL(url); HttpURLConnection conn = (HttpURLConnection) url_.openConnection(); conn.setConnectTimeout(3 * 1000); conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); ins = conn.getInputStream(); } catch (IOException e) { logger.info("图片读取失败!-->"+ e);} return ins;} / * Export Zip file * / public static void exportZipFile (String fileName, List fileUrl, HttpServletResponse response, HttpServletRequest request) {try {/ / browser handles garbled String userAgent = request.getHeader (" User-Agent ") / / filename.getBytes ("UTF-8") deals with safari garbled byte [] bytes = userAgent.contains ("MSIE")? FileName.getBytes (): fileName.getBytes ("UTF-8"); / / basically all browsers support ISO encoding fileName = new String (bytes, "ISO-8859-1"); / / double quotes outside the file name deal with the space truncation problem of firefox response.setHeader ("Content-disposition", String.format ("attachment; filename=\"% s\ ", fileName) Response.setContentType ("application/x-msdownload"); response.setCharacterEncoding ("UTF-8"); response.setHeader ("Content-Disposition", "attachment;filename=" + fileName); this.generateZipFile (response, fileUrl, fileName);} catch (Exception e) {logger.info ("download failed! -- > "+ e);} at this point, I believe you have a deeper understanding of" how to download Java package ", might as well come to the actual operation of it! here is the website, more related content can go to the relevant channels to query, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.