wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Jar compress with deep directory" Watch "Jar compress with deep directory" New topic
Author

Jar compress with deep directory

Gudavy Hu
Greenhorn

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);
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jar compress with deep directory
 
Similar Threads
creating jar file programatically
Out of Memory exception
creating jar using java.util.jar
how to jar the resulting .class files after compilation
JarInputStream