Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void createFile(File file) throws IOException {
- if (file.exists()) {
- return;
- }
- File parentFile = file.getParentFile();
- if (!parentFile.exists())
- parentFile.mkdirs();
- file.createNewFile();
- }
- public static void unzip(File archive, File output) throws IOException {
- byte[] buffer = new byte[1500];
- if (!output.exists()) {
- output.mkdir();
- }
- ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(archive)));
- ZipEntry ze;
- while ((ze = zis.getNextEntry()) != null) {
- File newFile = new File(output, ze.getName());
- if (!ze.isDirectory()) {
- createFile(newFile);
- BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(newFile));
- int len;
- while ((len = zis.read(buffer)) > 0)
- fos.write(buffer, 0, len);
- fos.close();
- }
- }
- zis.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment