ZIP文件系统提供程序将ZIP和JAR文件当作文件系统一样进行处理。
import java.io.IOException; import java.net.URI; /* from n o w j a v a . c o m - 时 代 Java */ import java.nio.file.DirectoryStream; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) { Map<String, String> attributes = new HashMap<>(); attributes.put("create", "true"); try { URI zipFile = URI.create("jar:file:/home.zip"); try (FileSystem zipFileSys = FileSystems.newFileSystem(zipFile, attributes);) { Path path = zipFileSys.getPath("docs"); Files.createDirectory(path); /** 来 自 n o w j a v a . c o m **/ try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(zipFileSys.getPath("/"));) {