UnzipFile cannot unzip files created by Windows
See original GitHub issueSteps to reproduce
- Create a folder ‘a’
- Create a subfolder within ‘a’ called ‘b’
- Create a file called ‘readme.txt’ in subfolder ‘b’
- Right click on folder ‘a’ and send to a compressed folder
- Attempt to unzip the zip file you have just created using unzip.java
Expected behaviour The file a/b/readme.txt is created.
Actual behaviour There is the following exception:
Exception in thread "main" java.io.FileNotFoundException: src/test/resources/unzipTest/a/b (No such file or directory)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
at java.io.FileOutputStream.<init>(FileOutputStream.java:162)
at com.baeldung.unzip.UnzipFile.main(UnzipFile.java:20)
Cause Not all software creates archives with all of the original folders and subfolders.
Linux zip command would create the following entires:
- a
- b (path a)
- readme.txt (path a/b)
Windows send to compressed folders would create the following entries:
- b (path a)
- readme.txt (path a/b)
From what I understand both are valid zip files, its just that the native zipping utility in Windows omits zip entries for folders in the root of the archive (I don’t know why).
Apache commons have a useful example which avoids this issue by checking for and, if necessary, creating the parent directories for each zip entry.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Can't Extract zipped Files with Windows 10 built in
Open file manager, highlight the zip file, right click then click "Open With"->More Apps->scroll down to end of list->click "Look for another ...
Read more >Tips to Fix Windows Cannot Complete the Extraction
You can fix this by moving the zip file to a different location like a different profile folder. From the new location, try...
Read more >Cannot unzip files created with Windows "Sent to compressed ...
I wrote different programs in scala using java.util.ZipFile, zip4j and apache commons compress library. zip4j returns: Exception in thread "main ...
Read more >How to unzip files in Windows 10 | PCWorld
File Explorer will open. Navigate to the location you'd like to extract the files and then click “Select Folder.” Once selected, click the...
Read more >How to unzip files on Windows (with built-in tools)
How to unzip a ZIP file archive, in Windows 11 and Windows 10, using the tools included in the operating system. How to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is a valid issue; I’ve added a fix in the linked PR: https://github.com/eugenp/tutorials/pull/10268
@thomasturrell we logged an internal ticket to investigate. I’ll follow up in here once we’ll get this resolved.