aspose file tools*
The moose likes Java in General and the fly likes java.io.zip cannot uzip what it zips Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.io.zip cannot uzip what it zips" Watch "java.io.zip cannot uzip what it zips" New topic
Author

java.io.zip cannot uzip what it zips

Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 319
My problem began deploying a war file in tomcat. I get the error:
java.io.FileNotFoundException: C:\MyWorkSpaces\X\A Swing Help System with CreateWebHelp_files\image001.png (The system cannot find the path specified)

The file is in the war file and if I change the extension to zip, WinZip constructs the directory correctly. If I zip the original directory wit WinZip, it deploys fine in Tomcat.

Tomcat uses java.io.zip to unzip, so i created a program to unzip and i get the same error. The code is:


I really need to write code to create the war file; your help will be greatly appreciated. If you can tell me another way to code zip I will appreciate it too.

Alejandro Barrero


Your help will be greatly appreciated,
Alejandro Barrero
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

The problem is that at least one folder could not be created. I guess something is wrong with the creation of the folder.

Now I could try to fix that, but it's not necessary. Folders are ZIP entries as well; use the isDirectory() function to test whether or not an entry is a directory.

I also added a bit of code to use a File object - it has some nice methods you can use.



SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 319
Rob:

Thank you very much, but that doesn't help. I created I zip file with my code, I added your suggested code:
[CODE}
protected void getFile(ZipEntry zipEntry) throws Exception {
String zipName = zipEntry.getName();
if (zipEntry.isDirectory())
{
createDirectory(zipName);
return;
}
File file = new File(this.unzipDirectory, zipName);
file.getParentFile().mkdirs();
// now the folder should really be there, unless you don't have the
// rights to write it or there was already a file with the same name
//String zipName = zipEntry.getName();
if (zipName.endsWith("/")) {
return;
}
if (zipName.startsWith("/")) {
zipName = zipName.substring(1);
}
// Create a directory if needed.
int locationOfLastSeparator = zipName.lastIndexOf("/");
if (locationOfLastSeparator != -1) {
String directoryRelativePath = zipName.substring(0, locationOfLastSeparator);
String directoryPath = this.unzipDirectory + File.separator + directoryRelativePath;
createDirectory(directoryPath);
}
FileOutputStream fileOutputStreamos = new FileOutputStream(
this.unzipDirectory + File.separator + zipName);
InputStream inputStream = this.workZipFile.getInputStream(zipEntry);
int characterCount = 0;
while ((characterCount = inputStream.read(this.byteBuffer)) > 0)
fileOutputStreamos.write(this.byteBuffer, 0, characterCount);
inputStream.close();
fileOutputStreamos.close();
}
[/CODE]
But I still have the same error.
Guido Sautter
Ranch Hand

Joined: Dec 22, 2004
Posts: 142
Could you post a stack trace of the error, so we can see which line of your code actually produces the exception? This might help a lot in finding the source or the problem ...
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 319
Well, my unzip started to work. Most probably it is because of the changes you suggested (apparently I missed the fact that it was working before). So, thanks for your suggestion.
Unfortunately, I still cannot deploy in Tomcat the war file that I zip. I am getting a long error message:
The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path C:\Program Files\Java\jdk1.6.0_02\bin;C:\Windows ...
Now I have to dig more and post the problem in an other forum.
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.io.zip cannot uzip what it zips