Java Zip File System Provider: ReadOnly on remote drive [Windows]

I have a problem with Zip File System Provider: If the zip file is on a remote drive (mapped or not seems to be irrelevant), the virtual file system is readonly, although the file itself is not. I wrote a minimal sample code:

public static void main(String[] args) throws IOException {
    File workingDir = new File(args[0]);
    File source = new File(workingDir, "");
    File target = new File(workingDir, "");
    Files.copy(source.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING);

    try (FileSystem zipfs = FileSystems.newFileSystem(target.toPath(), null)) {
        Path pathInZipfile = zipfs.getPath("test.xml");
        System.out.println("zipfile writable: " + target.canWrite());
        System.out.println("zipFS writable: " + !zipfs.isReadOnly());
        System.out.println("File successfully deleted");   
    } catch (IOException e) {

If workingDir is a local directory, everything works fine. However, if it is a (mapped) remote drive, i get:

zipfile writable: true
zipFS writable: false
Exception in thread "main" java.nio.file.ReadOnlyFileSystemException
    at com.sun.nio.zipfs.ZipFileSystem.checkWritable(
    at com.sun.nio.zipfs.ZipFileSystem.deleteFile(
    at com.sun.nio.zipfs.ZipPath.delete(
    at com.sun.nio.zipfs.ZipFileSystemProvider.delete(
    at java.nio.file.Files.delete(Unknown Source)
    at zipfs.ZipFS.main(

Am I doing something wrong? Is it impossible? Is there a workaround?


I ran into the same thing and I looked at the JDK code.


In there are three relevant lines:

zfpath.getFileSystem().provider().checkAccess(zfpath, AccessMode.READ);
if (!Files.isWritable(zfpath))
    this.readOnly = true;

zfPath is a Path object. Something in the Windows FileSystem provider blocks write access to a zip archive path. Doesn’t seem like there is much to be done about that.


What I used as a workaround was to:

  1. Create the zip archive in a temp folder
  2. Populate the zip archive
  3. Copy the temp file to the original mapped drive location

As long as the mapped drive is writable in contexts outside of the zip FileSystem, this method works.

Leave a Reply

Your email address will not be published. Required fields are marked *