Results 1 to 1 of 1
- 03-18-2009, 01:35 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 1
- Rep Power
- 0
Recreate directory structure when extracting from zip file
Using java.util.zip, I am unable to extract files in the exact directory structure as inside a zip file, I keep getting IOException: Parent of file is not a directory, below is the code, please advice.
Java Code:public static void extractZip(String zippath, String parentpath, String zipfilename) { try { ZipFile archive = new ZipFile(zippath); byte[] buffer = new byte[2048]; for ( Enumeration e = archive.entries(); e.hasMoreElements();) { ZipEntry entry = (ZipEntry) e.nextElement(); String filename = entry.getName(); File destFile = new File(parentpath+"/"+zipname+"/"+filename); if (destFile.exists()) { System.out.println("Overwrite not supported"); } else { String parent = destFile.getParent(); if (parent!=null) { File parentFile = new File(parent); if (!parentFile.exists()) { parentFile.mkdirs(); } } InputStream in = archive.getInputStream(entry); destFile.createNewFile(); OutputStream out = new FileOutputStream(destFile); int count; while((count=in.read(buffer)) != -1) out.write(buffer, 0, count); in.close(); out.close(); } } } catch(Exception e) {e.printStackTrace();} }Last edited by jimmy; 03-18-2009 at 01:38 PM.
Similar Threads
-
[SOLVED] File chooser selecting file from directory...?
By prabhurangan in forum AWT / SwingReplies: 12Last Post: 06-18-2008, 04:08 AM -
Extracting JAR file
By Java Tip in forum Java TipReplies: 0Last Post: 02-08-2008, 09:17 AM -
Extracting data from an XML file...
By techno_brains in forum New To JavaReplies: 1Last Post: 07-15-2007, 05:46 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks