zipinputstream

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;

System.IOException when opening file with File.OpenRead

走远了吗. 提交于 2019-12-11 17:26:42
问题 I get the following exception when I open a file for unzipping it's contents. It happens when I have the file selected in Windows Explorer, or mouse over it showing a tooltip. System.IO.IOException was unhandled Message=The process cannot access the file 'D:\Documents\AutoUnZip\Zips\MVCContrib.Extras.release.zip' because it is being used by another process. Source=mscorlib StackTrace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String

Java ZipInputStream extraction errors

耗尽温柔 提交于 2019-12-11 05:54:04
问题 Below is some code which extracts a file from a zip file containing only a single file. However, the extracted file does not match the same file extracted via WinZip or other zip utility. I expect that it might be off by a byte if the file contains an odd number of bytes (because my buffer is size 2 and I just abort once the read fails). However, when analyzing (using WinMerge or Diff) the file extracted with code below vs. file extracted via Winzip, there are several areas where bytes are

Unzipping with ZipInputStream never finishes

风流意气都作罢 提交于 2019-12-11 01:02:49
问题 I'm using an AsyncTask to unzip a file, and all seems to be going well (all the files in the ZIP archive are extracted), but my unzip method never finishes. Here's the source for my unzip class: public class MyUnzipper { public static boolean unzipFileIntoDirectory(String inputFilename, String outputPath) throws Exception { ZipInputStream zis = null; BufferedOutputStream dest = null; try { File archive = new File(inputFilename); File destinationDir = new File(outputPath); final int BUFFER

Finding a file in zipentry java

可紊 提交于 2019-12-10 17:13:00
问题 I am trying to find a file within a zip file and get it as an InputStream . So this is what I am doing to get it so far and I am not certain if I am doing it correctly. Here is a sample as the original is slightly longer but this is the main component... public InputStream Search_Image(String file_located, ZipInputStream zip) throws IOException { for (ZipEntry zip_e = zip.getNextEntry(); zip_e != null ; zip_e = zip.getNextEntry()) { if (file_located.equals(zip_e.getName())) { return zip; } if

How to reuse / reset an ZipInputStream?

时间秒杀一切 提交于 2019-12-10 16:12:17
问题 I want to reset the ZipInputStream (ie back to the start position) in order to read certain files in order. How do I do that? I am so stucked... ZipEntry entry; ZipInputStream input = new ZipInputStream(fileStream);//item.getInputStream()); int check =0; while(check!=2){ entry = input.getNextEntry(); if(entry.getName().toString().equals("newFile.csv")){ check =1; InputStreamReader inputStreamReader = new InputStreamReader(input); reader = new CSVReader(inputStreamReader); //read files //reset

unzip archive with subfolders in java?

∥☆過路亽.° 提交于 2019-12-08 11:01:47
问题 I am trying to unzip an archive (test.zip) containing a subfolder with some png images: test.zip | -> images | -> a.png | -> b.png Here is what I do: public static void unzip(String archive, File baseFolder, String[] ignoreExtensions) { FileInputStream fin; try { fin = new FileInputStream(archive); ZipInputStream zin = new ZipInputStream(fin); ZipEntry ze = null; while ((ze = zin.getNextEntry()) != null) { if (ignoreExtensions == null || !ignoreEntry(ze, ignoreExtensions)) { File

How to read data from nested zip files in Java without using temporary files?

感情迁移 提交于 2019-12-08 09:12:38
问题 I am trying to to extract files out of a nested zip archive and process them in memory. What this question is not about: How to read a zip file in Java: NO, the question is how to read a zip file within a zip file within a zip and so on and so forth (as in nested zip files). Write temporary results on disk: NO, I'm asking about doing it all in memory. I found many answers using the not-so-efficient technique of writing results temporarily to disk, but that's not what I want to do. Example:

How can I convert ZipInputStream to InputStream?

和自甴很熟 提交于 2019-12-07 08:16:43
问题 I have code, where ZipInputSream is converted to byte[], but I don't know how I can convert that to inputstream. private void convertStream(String encoding, ZipInputStream in) throws IOException, UnsupportedEncodingException { final int BUFFER = 1; @SuppressWarnings("unused") int count = 0; byte data[] = new byte[BUFFER]; while ((count = in.read(data, 0, BUFFER)) != -1) { // How can I convert data to InputStream here ? } } 回答1: ZipInputStream is a subclass of InputStream. http://download

extracting contents of ZipFile entries when read from byte[] (Java)

喜你入骨 提交于 2019-12-06 04:48:25
问题 I have a zip file whose contents are presented as byte[] but the original file object is not accessible . I want to read the contents of each of the entries. I am able to create a ZipInputStream from a ByteArrayInputStream of the bytes and can read the entries and their names. However I cannot see an easy way to extract the contents of each entry. (I have looked at Apache Commons but cannot see an easy way there either). UPDATE @Rich's code seems to solve the problem, thanks QUERY why do both