String tempJarName = fromJar.replaceAll(".jar", "")+toJarComp;
int response = JOptionPane.showOptionDialog(null, "Create file: "+tempJarName+" from "+fromJar+" and "+toJar+ " ?", "Confirm toolbox creation",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
if (response == JOptionPane.OK_OPTION) {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(tempJarName)); // this is your "out" variable
// copy the files from the old JAR to the new, but don't close the new JAR yet
ZipEntry inEnt;
while ((inEnt = in.getNextEntry()) != null) {
ZipEntry outEnt = new ZipEntry(inEnt); // copy size, modification time etc.
byte[] data = new byte[(int)inEnt.getSize()];
in.read(data); // read data for this old entry
in.closeEntry();
out.putNextEntry(outEnt);
out.write(data); // copy it to the new entry
out.closeEntry();
}
in.close();
in = new JarInputStream(new FileInputStream(toJar));
// copy the files from the old JAR to the new, but don't close the new JAR yet
while ((inEnt = in.getNextEntry()) != null) {
ZipEntry outEnt = new ZipEntry(inEnt); // copy size, modification time etc.
byte[] data = new byte[(int)inEnt.getSize()];
in.read(data); // read data for this old entry
in.closeEntry();
try{
out.putNextEntry(outEnt);
out.write(data); // copy it to the new entry
out.closeEntry();
}
catch (IOException ioe) {
System.out.println("exception trying to put entry "+outEnt.getName());
out.closeEntry();
}
}
// and *now* we close the new JAR file.
out.close();
in.close();
}
// We then delete the old JAR file...
//File origFile = new File(fromJar);
//boolean status = origFile.delete();