问题描述:

I am trying to determine if a zipEntry (of a zip file) is a directory or not but the test returns false.

//entryName is the name of a directory inside of the zip file

File file = new File (entryName);

if(file.isDirectory()){ ...}

网友答案:

Use the new ZIP filesystem provided by Java 7:

final Path path = Paths.get("/path/to/my.zip");
final String uri = "jar:" + path.toUri().toString();

try (
    final FileSystem fs = FileSystems.newFileSystem(URI.create(str),
       Collections.<String, String>emptyMap(), null);
) {
    return Files.isDirectory(fs.getPath("/path/into/zip/file"));
}
相关阅读:
Top