File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Jar compress with deep directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Jar compress with deep directory" Watch "Jar compress with deep directory" New topic

Jar compress with deep directory

Gudavy Hu

Joined: Apr 11, 2002
Posts: 7
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);
while ((bytesRead = != -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: 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.
I agree. Here's the link:
subject: Jar compress with deep directory
It's not a secret anymore!