question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnzipFile cannot unzip files created by Windows

See original GitHub issue

Steps to reproduce

  1. Create a folder ‘a’
  2. Create a subfolder within ‘a’ called ‘b’
  3. Create a file called ‘readme.txt’ in subfolder ‘b’
  4. Right click on folder ‘a’ and send to a compressed folder
  5. 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:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
lor6commented, Nov 20, 2020

This is a valid issue; I’ve added a fix in the linked PR: https://github.com/eugenp/tutorials/pull/10268

0reactions
maibincommented, Aug 13, 2019

@thomasturrell we logged an internal ticket to investigate. I’ll follow up in here once we’ll get this resolved.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found