• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jar compress with deep directory  RSS feed

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);
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.
Destiny's powerful hand has made the bed of my future. And this tiny ad:
Why should you try IntelliJ IDEA ?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!