Last active
July 15, 2016 13:53
-
-
Save takaki/318bee8f74e4879e501a3fb351ec7579 to your computer and use it in GitHub Desktop.
JavaでZIPファイルを扱う ref: http://qiita.com/takaki@github/items/3205cc96250deca449cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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