Unzip Zip File Using JAVA ZipFile Class -
i trying unzip files using java , compiling without errors. when calling tool, , giving absolute destination path , source path of file e.g: source: d:\data\test.zip destination: d:\data\op\
i getting error acess denied (i have admin access of system)
stack trace:
extracting: test/new text document - copy (2).txt java.io.filenotfoundexception: d:\data\op (access denied) @ java.io.fileoutputstream.open(native method) @ java.io.fileoutputstream.(fileoutputstream.java:179) @ java.io.fileoutputstream.(fileoutputstream.java:70)
below function calling, believe has destination may ot extracting absolute path temp folder cannot write. tried combination on destination not working form end.please guide me how can fix it.
public void unzip(string zipfilepath, string destdir, string flname) throws exception { int buffer = 2048;//buffer size try { file dir = new file(destdir); // throw exception if output directory doesn't exist if(!dir.exists()) { //print message in consol system.out.println("no destination directory exists unzip operation."); throw new exception(); } bufferedoutputstream dest = null; bufferedinputstream = null; zipentry entry; zipfile zipfile = new zipfile(zipfilepath); enumeration e = zipfile.entries(); while(e.hasmoreelements()) { entry = (zipentry) e.nextelement(); system.out.println("extracting: " +entry); = new bufferedinputstream (zipfile.getinputstream(entry)); int count; byte data[] = new byte[buffer]; fileoutputstream fos = new fileoutputstream(destdir); dest = new bufferedoutputstream(fos, buffer); while ((count = is.read(data, 0, buffer)) != -1) { dest.write(data, 0, count); } //close streams dest.flush(); dest.close(); is.close(); } } catch(exception e) { e.printstacktrace(); throw new exception(); } }
you trying write directory
fileoutputstream fos = new fileoutputstream(destdir);
try changing
fileoutputstream fos = new fileoutputstream(destdir + file.separator + entry.getname ());
using zipfile entry
's name
Comments
Post a Comment