• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

java.io.zip cannot uzip what it zips

 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22682
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic