Skip to content

Instantly share code, notes, and snippets.

@takaki
Last active July 15, 2016 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takaki/318bee8f74e4879e501a3fb351ec7579 to your computer and use it in GitHub Desktop.
Save takaki/318bee8f74e4879e501a3fb351ec7579 to your computer and use it in GitHub Desktop.
JavaでZIPファイルを扱う ref: http://qiita.com/takaki@github/items/3205cc96250deca449cc
public class ZipDemo {
public static final String PATH = "/path/to/zipfile.zip";
public static void main(final String[] args) throws IOException {
final Path zipfile = Paths.get(PATH);
try (ZipInputStream zis = new ZipInputStream(
new ByteArrayInputStream(Files.readAllBytes(zipfile)));) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (entry.isDirectory()) {
continue;
}
System.out.printf("%s - %d\n", entry.getName(),
IOUtils.toByteArray(zis).length);
}
}
}
}
public class ZipDemo {
public static final String PATH = "/path/to/zipfile.zip";
public static void main(final String[] args) throws IOException {
final Path zipfile = Paths.get(PATH);
try (FileSystem fs = FileSystems.newFileSystem(zipfile, null)) {
final Path path = fs.getPath("/");
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(final Path file,
final BasicFileAttributes attrs) throws IOException {
System.out.printf("%s - %d\n", file,
Files.readAllBytes(file).length);
return FileVisitResult.CONTINUE;
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment