@Test public void testUnzipFile() throws IOException { final File destDir = buildOrnidroidHomeTest(TEST_DIRECTORY + "/destDir"); final File srcZip = new File("./src/test/resources/audio/audio.zip"); final File destZip = new File(destDir.getAbsolutePath() + File.separator + "audio.zip"); FileHelper.doCopyFile(srcZip, destZip); FileHelper.unzipFile("audio.zip", destDir.getAbsolutePath()); }
public static boolean unzipFile(String zipname, String destDir) { InputStream is; ZipInputStream zis; try { String filename; is = new FileInputStream(destDir + File.separator + zipname); zis = new ZipInputStream(new BufferedInputStream(is)); ZipEntry ze; byte[] buffer = new byte[1024]; int count; while ((ze = zis.getNextEntry()) != null) { filename = ze.getName(); if (ze.isDirectory()) { File fmd = new File(destDir + File.separator + filename); fmd.mkdirs(); continue; } else { File ff = new File(destDir + File.separator + filename); if (!ff.getParentFile().exists()) { ff.getParentFile().mkdirs(); } FileOutputStream fout = new FileOutputStream(ff); while ((count = zis.read(buffer)) != -1) { fout.write(buffer, 0, count); } fout.close(); zis.closeEntry(); } } zis.close(); } catch (IOException e) { e.printStackTrace(); return false; } return true; }
FileHelper { public static boolean unzipFile(String zipname, String destDir) { InputStream is; ZipInputStream zis; try { String filename; is = new FileInputStream(destDir + File.separator + zipname); zis = new ZipInputStream(new BufferedInputStream(is)); ZipEntry ze; byte[] buffer = new byte[1024]; int count; while ((ze = zis.getNextEntry()) != null) { filename = ze.getName(); if (ze.isDirectory()) { File fmd = new File(destDir + File.separator + filename); fmd.mkdirs(); continue; } else { File ff = new File(destDir + File.separator + filename); if (!ff.getParentFile().exists()) { ff.getParentFile().mkdirs(); } FileOutputStream fout = new FileOutputStream(ff); while ((count = zis.read(buffer)) != -1) { fout.write(buffer, 0, count); } fout.close(); zis.closeEntry(); } } zis.close(); } catch (IOException e) { e.printStackTrace(); return false; } return true; } }
FileHelper { public static boolean unzipFile(String zipname, String destDir) { InputStream is; ZipInputStream zis; try { String filename; is = new FileInputStream(destDir + File.separator + zipname); zis = new ZipInputStream(new BufferedInputStream(is)); ZipEntry ze; byte[] buffer = new byte[1024]; int count; while ((ze = zis.getNextEntry()) != null) { filename = ze.getName(); if (ze.isDirectory()) { File fmd = new File(destDir + File.separator + filename); fmd.mkdirs(); continue; } else { File ff = new File(destDir + File.separator + filename); if (!ff.getParentFile().exists()) { ff.getParentFile().mkdirs(); } FileOutputStream fout = new FileOutputStream(ff); while ((count = zis.read(buffer)) != -1) { fout.write(buffer, 0, count); } fout.close(); zis.closeEntry(); } } zis.close(); } catch (IOException e) { e.printStackTrace(); return false; } return true; } private  FileHelper(); }
FileHelper { public static boolean unzipFile(String zipname, String destDir) { InputStream is; ZipInputStream zis; try { String filename; is = new FileInputStream(destDir + File.separator + zipname); zis = new ZipInputStream(new BufferedInputStream(is)); ZipEntry ze; byte[] buffer = new byte[1024]; int count; while ((ze = zis.getNextEntry()) != null) { filename = ze.getName(); if (ze.isDirectory()) { File fmd = new File(destDir + File.separator + filename); fmd.mkdirs(); continue; } else { File ff = new File(destDir + File.separator + filename); if (!ff.getParentFile().exists()) { ff.getParentFile().mkdirs(); } FileOutputStream fout = new FileOutputStream(ff); while ((count = zis.read(buffer)) != -1) { fout.write(buffer, 0, count); } fout.close(); zis.closeEntry(); } } zis.close(); } catch (IOException e) { e.printStackTrace(); return false; } return true; } private  FileHelper(); static void createEmptyFile(final File file); static int folderSize(File directory, boolean recursive); static void doCopyFile(final File srcFile, final File destFile); static void forceDelete(final File file); static void forceMkdir(final File directory); static void moveDirectory(final File srcDir, final File destDir); static String[] parseContentFile(final File contentFile); static void writeStringToFile(final File file, final String data,
			final Charset encoding, final boolean append); static boolean unzipFile(String zipname, String destDir); static int getFileSizeInMb(File downloadedFile); static int getCountFiles(File fileToCheck); }
FileHelper { public static boolean unzipFile(String zipname, String destDir) { InputStream is; ZipInputStream zis; try { String filename; is = new FileInputStream(destDir + File.separator + zipname); zis = new ZipInputStream(new BufferedInputStream(is)); ZipEntry ze; byte[] buffer = new byte[1024]; int count; while ((ze = zis.getNextEntry()) != null) { filename = ze.getName(); if (ze.isDirectory()) { File fmd = new File(destDir + File.separator + filename); fmd.mkdirs(); continue; } else { File ff = new File(destDir + File.separator + filename); if (!ff.getParentFile().exists()) { ff.getParentFile().mkdirs(); } FileOutputStream fout = new FileOutputStream(ff); while ((count = zis.read(buffer)) != -1) { fout.write(buffer, 0, count); } fout.close(); zis.closeEntry(); } } zis.close(); } catch (IOException e) { e.printStackTrace(); return false; } return true; } private  FileHelper(); static void createEmptyFile(final File file); static int folderSize(File directory, boolean recursive); static void doCopyFile(final File srcFile, final File destFile); static void forceDelete(final File file); static void forceMkdir(final File directory); static void moveDirectory(final File srcDir, final File destDir); static String[] parseContentFile(final File contentFile); static void writeStringToFile(final File file, final String data,
			final Charset encoding, final boolean append); static boolean unzipFile(String zipname, String destDir); static int getFileSizeInMb(File downloadedFile); static int getCountFiles(File fileToCheck); static final long ONE_KB; static final long ONE_MB; }