Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.io.zip cannot uzip what it zips

 
Alejandro Barrero
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Alejandro Barrero
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 335
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic