In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to deal with the java file stream. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
The processing files of the java file stream are packaged into zip1, downloaded to the local public void download (HttpServletResponse response) {String filePath = ""; / / the file path String fileName = ""; / / the file name / / read into the stream InputStream inStream = new FileInputStream (filePath); / / set the format of the output response.reset (); response.setContentType ("bin"); response.addHeader ("Content-Disposition", "attachment") Filename=\ "+ fileName +"\ "); IOUtils.copy (inStream, response.getOutputStream ());} 2, java backend download
Method 1:
New URL (fileUrl + item.getcBhFileserver ()) .openStream ()
Method 2:
Public Boolean addFile (String url, String id, String fileName) {RequestCallback requestCallBack = new RequestCallback () {@ Override public void doWithRequest (ClientHttpRequest request) throws IOException {request.getHeaders () .add ("accept", MediaType.APPLICATION_OCTET_STREAM_VALUE);}} ResponseExtractor responseExtractor = new ResponseExtractor () {@ Override public Boolean extractData (ClientHttpResponse response) throws IOException {if (response.getStatusCode () = = HttpStatus.OK) {/ / get the file stream InputStream input = response.getBody (); return true;} return false }}; return restTemplate.execute (url, HttpMethod.GET, requestCallBack, responseExtractor, id);} 3. The file is packaged into zippublic void zipFilesAll () throws Exception {String zipPath = ""; / / zip package path String zipFileName = ""; / / zip package name File zipFile = new File (zipFileName. ToString ()); / / create FileOutputStream object FileOutputStream fileOutputStream = null / / create ZipOutputStream ZipOutputStream zipOutputStream = null; try {/ / create a folder zipFile = new File (zipPath); FileUtils.forceMkdir (zipFile); / / create a file zipFile = new File (zipFileName. ToString ()); if (! zipFile.exists ()) {zipFile.createNewFile () } / / instantiate FileOutputStream object fileOutputStream = new FileOutputStream (zipFileName.toString ()); / / instantiate ZipOutputStream object zipOutputStream = new ZipOutputStream (fileOutputStream); / / create ZipEntry object ZipEntry zipEntry = null For (CL cl: ClList) {/ / instantiate the ZipEntry object, the current file in the source file array zipEntry = new ZipEntry (tCltjjl.getcClmc () + ".zip"); zipOutputStream.putNextEntry (zipEntry); IOUtils.copy (new FileInputStream (cl.getcPath (), zipOutputStream) }} catch (Exception e) {} finally {/ / remember to delete files}} background multiple files are packaged into zip return streams the foreground provides one-click download button
Add QR code operations to project pom files, and maven support for file packaging:
Net.glxn.qrgen javase 2.0 org.apache.commons commons-compress 1.12
Foreground code:
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.