Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error opening zip file created using java

I created a small application to read some files from the disk and zip it using java.util.zip.ZipOutputStream. It is successfully creating the zip file. But in windows when i try to open it / extract it am getting the error message like "Windows has blocked access to these files to help protect your computer". I am zipping only csv files. But if i try to unzip using the zipinputstream class from java itself, its unzipping it correctly. Can anyone throw some light on it.

regards, Anoop

like image 854
Anoop Avatar asked Dec 17 '22 20:12

Anoop


1 Answers

I know this post was several years ago. However, I hit something very similar in just using java.util.zip for the first time, and this post lead me to resolve the issue.

Anoop's last comment about absolute paths helped me find the problem. Since I didn't see the answer in searching several posts, I wanted to post it here - actually responding to Roland's last question:

The issue was when I used ZipEntry(file) with a fully qualified path/file, instead of a relative path. I couldn't open the resulting ZIP with any of my Windows OS instances. However, I could extract the file again with Java. It wasn't until I opened the zip with 7zip that I realized the issue. The first folder in my result.zip file was "D:". My directory was a long path under my D drive. So when opening my "Results.zip" file, here's what I would see after clicking down the directory tree in the zip file (from 7zip): Results.zip\D:\Apps\vertigo\instance5\runtime\myManager\discoveryResources\data

The "data" directory actually held all the files/directories that I zipped.

When I stripped off the path from the data directory, the Results.zip started with "data" instead of "D:". And that file could be opened with Windows 7, 2012, etc.

Hope it helps someone in the future.

Thanks, -Chris

like image 152
Chris Avatar answered Jan 03 '23 02:01

Chris