newFileSystem
static factory methods can be used to: scheme
that identifies the ZIP file system is jar
. view
named "zip
" that defines the following file attribute: The "permissions" attribute is the set of access permissions that are optionally stored for entries in a Zip file. The value of the attribute is
Name Type permissions Set
<PosixFilePermission
>
null
for entries that do not have access permissions. Zip file systems do not enforce access permissions. The "permissions" attribute may be read and set using the Files.getAttribute and Files.setAttribute methods. The following example uses these methods to read and set the attribute:
Set<PosixFilePermission> perms = Files.getAttribute(entry, "zip:permissions");
if (perms == null) {
perms = PosixFilePermissions.fromString("rw-rw-rw-");
Files.setAttribute(entry, "zip:permissions", perms);
}
In addition to the "zip
" view, a Zip file system optionally supports the PosixFileAttributeView
("posix
"). This view extends the "basic
" view with type safe access to the owner
, group-owner
, and permissions
attributes. The "posix
" view is only supported when the Zip file system is created with the provider property "enablePosixFileAttributes
" set to "true
". The following creates a file system with this property and reads the access permissions of a file:
var env = Map.of("enablePosixFileAttributes", "true");
try (FileSystem fs = FileSystems.newFileSystem(file, env) {
Path entry = fs.getPath("entry");
Set<PosixFilePermission> perms = Files.getPosixFilePermissions(entry);
}
The file owner and group owner attributes are not persisted, meaning they are not stored in the zip file. The "defaultOwner
" and "defaultGroup
" provider properties (listed below) can be used to configure the default values for these attributes. If these properties are not set then the file owner defaults to the owner of the zip file, and the group owner defaults to the zip file's group owner (or the file owner on platforms that don't support a group owner).
The "permissions
" attribute is not optional in the "posix
" view so a default set of permissions are used for entries that do not have access permissions stored in the Zip file. The default set of permissions are
defaultPermissions
" property described below. Property Name | Data Type | Default Value | Description |
---|---|---|---|
create |
String or Boolean
| false | If the value is true , the Zip file system provider creates a new Zip or JAR file if it does not exist. |
encoding | String | UTF-8 | The value indicates the encoding scheme for the names of the entries in the Zip or JAR file. |
enablePosixFileAttributes |
String or Boolean
| false | If the value is true , the Zip file system will support the PosixFileAttributeView . |
defaultOwner |
UserPrincipal or String
| null/unset | Override the default owner for entries in the Zip file system. The value can be a UserPrincipal or a String value that is used as the UserPrincipal's name. |
defaultGroup |
GroupPrincipal or String
| null/unset | Override the default group for entries in the Zip file system. The value can be a GroupPrincipal or a String value that is used as the GroupPrincipal's name. |
defaultPermissions |
Set <PosixFilePermission >or String
| null/unset | Override the default Set of permissions for entries in the Zip file system. The value can be a Set <PosixFilePermission > ora String that is parsed by PosixFilePermissions::fromString |
compressionMethod | String | "DEFLATED" | The value representing the compression method to use when writing entries to the Zip file system.
|
releaseVersion |
String or Integer
| null/unset | A value representing the version entry to use when accessing a multi-release JAR. If the JAR is not a multi-release JAR, the value will be ignored and the JAR will be considered un-versioned. The value must be either the string "runtime" or represent a valid Java SE Platform version number, such as
|
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"));
Path rootDir = zipfs.getPath("/");
Files.walk(rootDir)
.forEach(System.out::println);
Type | Description |
---|---|
FileSystemProvider | Service-provider class for file systems. |
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/jdk.zipfs/module-summary.html