Module jdk.zipfs
Provides the implementation of the Zip file system provider.
The Zip file system provider treats the contents of a Zip or JAR file as a file system.
Accessing a Zip File System
The FileSystemsnewFileSystem
static factory methods can be used to:
- Create a Zip file system
- Open an existing file as a Zip file system
URI Scheme Used to Identify the Zip File System
The URIscheme that identifies the ZIP file system is jar.
Zip File System Properties
The following properties may be specified when creating a Zip file system:
| Property Name | Data Type | Default Value | Description |
|---|---|---|---|
| create | java.lang.String | false |
If the value is true, the Zip file system provider
creates a new Zip or JAR file if it does not exist.
|
| encoding | java.lang.String | UTF-8 | The value indicates the encoding scheme for the names of the entries in the Zip or JAR file. |
Examples:
Construct a new Zip file system that is identified by a URI. If the Zip file does not exist, it will be created:
URI uri = URI.create("jar:file:/home/luckydog/tennisTeam.zip");
Map<String, String> env = Map.of("create", "true");
FileSystem zipfs = FileSystems.newFileSystem(uri, env);
Construct a new Zip file system that is identified by specifying a path
and using automatic file type detection. Iterate from the root of the JAR displaying each
found entry:
FileSystem zipfs = FileSystems.newFileSystem(Path.of("helloworld.jar"), null);
Path rootDir = zipfs.getPath("/");
Files.walk(rootDir)
.forEach(System.out::println);
-
-
Services
Provides Type Description FileSystemProvider
-
