{"id":5969,"date":"2014-04-11T06:53:58","date_gmt":"2014-04-11T06:53:58","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/11\/how-to-unzip-a-zip-folder-containing-different-file-formats-using-java-collection-of-common-programming-errors\/"},"modified":"2014-04-11T06:53:58","modified_gmt":"2014-04-11T06:53:58","slug":"how-to-unzip-a-zip-folder-containing-different-file-formats-using-java-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/11\/how-to-unzip-a-zip-folder-containing-different-file-formats-using-java-collection-of-common-programming-errors\/","title":{"rendered":"How to unzip a zip folder containing different file formats using Java-Collection of common programming errors"},"content":{"rendered":"<p>This is a good example in which he showed to unzip all the formats (pdf, txt etc) have look its quite<\/p>\n<p>or you can use this code might work (i haven&#8217;t tried this)<\/p>\n<pre><code>import java.io.BufferedOutputStream;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.util.zip.ZipEntry;\nimport java.util.zip.ZipInputStream;\n\npublic class ZipUtils\n{\n  private static final int  BUFFER_SIZE = 4096;\n\n  private static void extractFile(ZipInputStream in, File outdir, String name) throws IOException\n  {\n    byte[] buffer = new byte[BUFFER_SIZE];\n    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(outdir,name)));\n    int count = -1;\n    while ((count = in.read(buffer)) != -1)\n      out.write(buffer, 0, count);\n    out.close();\n  }\n\n  private static void mkdirs(File outdir,String path)\n  {\n    File d = new File(outdir, path);\n    if( !d.exists() )\n      d.mkdirs();\n  }\n\n  private static String dirpart(String name)\n  {\n    int s = name.lastIndexOf( File.separatorChar );\n    return s == -1 ? null : name.substring( 0, s );\n  }\n\n  \/***\n   * Extract zipfile to outdir with complete directory structure\n   * @param zipfile Input .zip file\n   * @param outdir Output directory\n   *\/\n  public static void extract(File zipfile, File outdir)\n  {\n    try\n    {\n      ZipInputStream zin = new ZipInputStream(new FileInputStream(zipfile));\n      ZipEntry entry;\n      String name, dir;\n      while ((entry = zin.getNextEntry()) != null)\n      {\n        name = entry.getName();\n        if( entry.isDirectory() )\n        {\n          mkdirs(outdir,name);\n          continue;\n        }\n        \/* this part is necessary because file entry can come before\n         * directory entry where is file located\n         * i.e.:\n         *   \/foo\/foo.txt\n         *   \/foo\/\n         *\/\n        dir = dirpart(name);\n        if( dir != null )\n          mkdirs(outdir,dir);\n\n        extractFile(zin, outdir, name);\n      }\n      zin.close();\n    } \n    catch (IOException e)\n    {\n      e.printStackTrace();\n    }\n  }\n}\n<\/code><\/pre>\n<p>Regards<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a good example in which he showed to unzip all the formats (pdf, txt etc) have look its quite or you can use this code might work (i haven&#8217;t tried this) import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class ZipUtils { private static final int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5969","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5969","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5969"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5969\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5969"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5969"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}