• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Jar compress with deep directory  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to compress many files into a .jar file. These files to be compressed are distributed in different depth directories. I am using the JarInputStream and JarOutputStream as foloowing:
public void createJar(String fileName, File file)
throws Exception {
FileOutputStream out = new FileOutputStream(fileName);
FileInputStream fis = null;
JarOutputStream jar = new JarOutputStream(out, new Manifest());
try {
byte[] buffer = new byte[1024];
int bytesRead;
String files[] = file.list();
for (int i = 1; i < files.length; i++) {
String fileName = files[i];
fis = new FileInputStream(fileName);
JarEntry entry = new JarEntry(fileName);
jar.putNextEntry(entry);
while ((bytesRead = fis.read(buffer)) != -1) {
jar.write(buffer, 0, bytesRead);
}
}
} catch (IOException io) {
throw new Exception("In JarFileManager createJar() method");
} finally {
if(fis != null){ fis.close(); }
if(jar != null){ jar.close(); }
}
But it does not work. I got a Exception:
java.io.FileNotFoundException: Your.jar (The system cannot find the file specified)
"Your.jar" is the parameter I passed to the above method as "fileName" it is given in full path (c:/..../your.jar).
What is wrong? Can any people help me?
Thanks very much.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!