I have a Path to zip file on virtual filesystem (jimfs) and I need to open this zip file using ZipFile.
But there is no constructor in ZipFile to get Path as argument, only File.
However, I can't create from my Path a File (path.toFile()) because I get UnsupportedOperationException. How can I open my zip file with ZipFile? Or maybe there are other ways of working with zip files which are not on default filesystem?
The
ZipFileclass is limited to files in the file-system.An alternative would be to use
ZipInputStreaminstead. Create anInputStreamfrom yourPathusingand the use the
InputStreamto create anZipInputStream. This way should work as expected:So the recommended way to use it is:
Note that decompressing certain ZIP files using
ZipInputStreamwill fail because of their ZIP structure. This is a technical limitation of the ZIP format and can't be solved. In such cases you have to create a temporary file in file-system or memory and use a different ZIP class likeZipFile.