zipoutputstream

Zip subfolders using ZipOutputStream

旧巷老猫 提交于 2019-12-19 03:20:49
问题 ZipOutputStream only zips files in a folder. I want to zip subfolders also. How can I achieve this? 回答1: You have to recursively explore your directory in order to add all files in the zip. See this small helper if you wish: using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.SharpZipLib.Checksums; using System.IO; using System; using System.Collections.Generic; using System.Text; using System.Collections; using System.Text.RegularExpressions; namespace Zip { /// <summary> /// Uses

Serve Zip of generated Zips to Client

怎甘沉沦 提交于 2019-12-13 04:08:34
问题 I'm generating a ZIP file that contains a bunch of autogenerated XML files. Recently requirements changed and now i must generate several times that ZIP (with variations on XML data) and serve them directly to client without using actual files in server. This is what im doing: // [... servlet handling ... ] response.setContentType("application/zip"); response.setHeader("Content-Disposition", "attachment;filename=cierresZ_a_tangonet" + java.time.LocalDate.now() + ".zip"); // stream straight to

How can I avoid mutable variables in Scala when using ZipInputStreams and ZipOutpuStreams?

牧云@^-^@ 提交于 2019-12-12 08:19:29
问题 I'm trying to read a zip file, check that it has some required files, and then write all valid files out to another zip file. The basic introduction to java.util.zip has a lot of Java-isms and I'd love to make my code more Scala-native. Specifically, I'd like to avoid the use of vars . Here's what I have: val fos = new FileOutputStream("new.zip"); val zipOut = new ZipOutputStream(new BufferedOutputStream(fos)); while (zipIn.available == 1) { val entry = zipIn.getNextEntry if (entryIsValid

How to create compressed Zip archive using ZipOutputStream so that method getSize() of ZipEntry returns correct size?

末鹿安然 提交于 2019-12-12 07:59:18
问题 Consider the code example that put a single file test_file.pdf into zip archive test.zip and then read this archive: import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; public class Main { public static void main(String[] args) { File infile = new File("test_file.pdf"); try ( FileInputStream fis = new FileInputStream(infile); ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("test.zip")); ) { int bytesRead;

HTML5 multiple file downloader : looking for better option than single Zip via ZipOutputStream [closed]

淺唱寂寞╮ 提交于 2019-12-12 06:39:20
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I have a requirement to upload and download multiple files. jquery.filedrop.js seems to handle the HTML5 multiple file uploading but I haven't seen anything for multiple downloading. I can stick the files into a Zip using ZipOutputStream, but this isn't as nice UX as simply drag-drop to the filesystem unzipped.

Java: how to compress a byte[] using ZipOutputStream without intermediate file

两盒软妹~` 提交于 2019-12-11 15:39:57
问题 Requirement: compress a byte[] to get another byte[] using java.util.zip.ZipOutputStream BUT without using any files on disk or in-memory(like here https://stackoverflow.com/a/18406927/9132186). Is this even possible? All the examples I found online read from a file(.txt) and write to a file(.zip). ZipOutputStream needs a ZipEntry to work with and that ZipEntry needs a file. However, my use case is as follows: I need to compress a chunk (say 10MB) of a file at a time using a zip format and

Error java.util.zip.ZipException: invalid entry size while copying image (.png) from 1 zip file to another

天涯浪子 提交于 2019-12-11 00:57:48
问题 I'm trying to modify an existing .zip file and then creating a modified copy. I can easily do that to all files except for a .png file in the zip file, which results in error java.util.zip.ZipException: invalid entry compressed size (expected 113177 but got 113312 bytes) The following code is what I'm trying to run to simply copy a .png image from dice.zip and adding it to diceUp.zip. public class Test { public static void main(String[] args) throws IOException{ ZipFile zipFile = new ZipFile(

Using a servlet, how do you download multiple files from a database and zip them for client download

北慕城南 提交于 2019-12-07 05:04:36
问题 I have a jsp/servlet web app in which the client can choose a "course" and an "assignment" via dropdown boxes, and then click a button to download all the files in the database that are listed under that course/assignment combination. The servlet code isn't quite working, as the zip file is not being sent to the browser as an attachment. I do have working code for downloading one file at a time, but something is getting stuck with this code for zipping the files. All the files in the database

How do you add a folder to a zip archive with ICSharpCode.SharpZipLib

折月煮酒 提交于 2019-12-07 02:57:48
问题 I have to create two folders inside of a zip file that I create programmatically using ICSharpCode.SharZipLib.Zip . I want to: private void AddToZipStream(byte[] inputStream, ZipOutputStream zipStream, string fileName, string fileExtension) { var courseName = RemoveSpecialCharacters(fileName); var m_Bytes = inputStream; if ((m_Bytes != null) && (zipStream != null)) { var newEntry = new ZipEntry(ZipEntry.CleanName(string.Concat(courseName, fileExtension))); newEntry.DateTime = DateTime.Now;

Android append files to a zip file without having to re-write the entire zip file?

限于喜欢 提交于 2019-12-06 04:12:56
问题 How can I append files to an existing zip file? I already have the code that can create a zip file and it works great except for one big problem. The way it works now, the user takes a bunch of pictures, and at the end, all the pictures get added to a zip file, which can take quite a while if you take enough pictures. :-( So I'm thinking, I have a very good and efficient solution. As the pictures are taken, I will simply add the each new picture to the zip file right after it's taken. Then