In the past few days, one click operation needs to generate downloads of multiple files, which is theoretically not feasible. A request must have only one response. Therefore, You Need To package multiple files into a zip package before downloading them. After searching the Internet, you can use the ZipOutputStream class. At the beginning, the author did not know how to use java.util.zip. ZipOutputStream. Later, I found that although the generated files are not garbled on the server end, after the files are added to the zip package, they are downloaded from the client, the obtained Chinese file names are garbled. So I thought it would be okay to change the encoding. After a few days, I found that java.util.zip. ZipOutputStream lacks encoding conversion. Chinese garbled characters cannot be solved. Search again and find that apachealso has an org.apache.tools.zip. ZipOutputStream. The method declaration is the same. So I changed the Reference Path of the class and ran it. Success !!!!
Mark usage
String zipfilename = "result.zip" String zipfilepath = storagePath + ZipOutputStream zos = ZipOutputStream (! File. exists () {BufferedWriter bw = BufferedWriter (OutputStreamWriter (FileOutputStream (file), "UTF-8"); bw. write (sb. toString (); ZipEntry ze = ZipEntry (file. getName (); BufferedInputStream bis = BufferedInputStream (len = bis. read (buf)> 0 zos. write (buf, 0 zos. close (); View Code