-
-
Save oldshensheep/bea5bd4c313f27884bc87dced9917bf6 to your computer and use it in GitHub Desktop.
java unzip
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
import java.io.File; | |
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.StandardOpenOption; | |
import java.util.zip.ZipFile; | |
public class S { | |
public static void main(String[] args) throws IOException { | |
f("abc.zip", "./"); | |
} | |
public static void f(String filePath, String dst) throws IOException { | |
try (ZipFile zipFile = new ZipFile(filePath);) { | |
String destDir = "./"; | |
zipFile.stream().forEach(zipEntry -> { | |
if (zipEntry.isDirectory()) { | |
if (new File(destDir, zipEntry.getName()).mkdirs()) { | |
// Handle errors | |
} | |
} else { | |
try (var fos = Files.newOutputStream(new File(destDir, zipEntry.getName()).toPath(), | |
StandardOpenOption.CREATE_NEW);) { | |
fos.write(zipEntry.getExtra()); | |
} catch (IOException e) { | |
// Handle errors | |
} | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment