Access Denied when extracting zip file.
I'm attempting to create an installer of sorts. When created, everything is stored inside a zip file named DATA.mpk and then put inside the jarfile for distribution.
The structure looks like this
Jar.jar
--DATA.mpk
----INJAR
------files
----mc
------files
--classes
Here's my current extraction code:
Code :
//DATA.mpk
System.out.println(dataDir.canRead() + ":" + dataDir.canWrite() + ":" + dataDir.canExecute());
try
{
//gimme
copyInputStream(Extractor.class.getResourceAsStream("DATA.mpk"), new BufferedOutputStream(new FileOutputStream(".DATA.mpk")));
//nowgo
ZipFile zipFile = new ZipFile(".DATA.mpk");
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while(entries.hasMoreElements()) {
String path = "DATA/";
ZipEntry entry = (ZipEntry)entries.nextElement();
if(!entry.getName().contains("META-INF")){
File file = new File(entry.getName());
try{
if(file.getParent() != null);
StringBuilder finalPath = new StringBuilder();
finalPath.append("DATA/");
String[] structure = entry.getName().split("/");
for (int i=0; i<structure.length -1; i++){
finalPath.append(structure[i]).append("/");
}
File parentDir = new File(finalPath.toString());
parentDir.mkdirs();
}catch(Exception e){
}
System.out.println("Extracting datafile: " + entry.getName());
copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(path + entry.getName())));
}else{
continue;
}
}
zipFile.close();
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
File df = new File("DATA.mpk");
df.delete();
According to the debug line, I have read/write/execute permissions on the directory, but when it attempts to extract the INJAR folder, it throws FileNotFoundException (Access is denied).
Not sure where the issue is. There's a clause before the above code that successfully unzips a jarfile already on my computer, I'm adding stuff to it using the above clause and then re-zipping everything up.
Here's the exact error:
Code :
true:true:true
java.io.FileNotFoundException: DATA\INJAR (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at techwiz24.McRepack.Extractor.Extractor$install.doInstall(Extractor.java:210)
at techwiz24.McRepack.Extractor.Extractor$install.run(Extractor.java:98)
at techwiz24.McRepack.Extractor.Extractor$install.doAction(Extractor.java:111)
at techwiz24.McRepack.Extractor.Extractor$2.actionPerformed(Extractor.java:78)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)Extracting datafile: INJAR/
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Re: Access Denied when extracting zip file.
Nevermind :P I had already created the directory in the code. Crap...