4

is there a ZipOutputStream setLevel(9) equivalent in JAVA NIOs ZIP FileSystem? Thanks in advance.

dforce
  • 2,136
  • 3
  • 20
  • 36

1 Answers1

1

The documentation gives an example of how to use the Zip File System Provider:

import java.util.*;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.*;

public class ZipFSPUser {
    public static void main(String [] args) throws Throwable {
        Map<String, String> env = new HashMap<>(); 
        env.put("create", "true");
        // locate file system by using the syntax 
        // defined in java.net.JarURLConnection
        URI uri = URI.create("jar:file:/codeSamples/zipfs/zipfstest.zip");

        try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
            Path externalTxtFile = Paths.get("/codeSamples/zipfs/SomeTextFile.txt");
            Path pathInZipfile = zipfs.getPath("/SomeTextFile.txt");          
            // copy a file into the zip file
            Files.copy( externalTxtFile,pathInZipfile, 
                    StandardCopyOption.REPLACE_EXISTING ); 
        } 
    }
}

As you can see there is an Map<String, String> environment variable used to set the zip properties. But for now, as defined in this documentation page, there is only two options: create to define if a new zip file should be created if it does not exist, and encoding to define the encoding scheme.

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240