我有一個WAR文件,需要添加兩個文件。目前,我正在這樣做:如何更新預先存在的Jar文件
File war = new File(DIRECTORY, "server.war");
JarOutputStream zos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(war)));
//Add file 1
File file = new File(DIRECTORY, "file1.jar");
InputStream is = new BufferedInputStream(new FileInputStream(file));
ZipEntry e = new ZipEntry("file1.jar");
zos.putNextEntry(e);
byte[] buf = new byte[1024];
int len;
while ((len = is.read(buf, 0, buf.length)) != -1) {
zos.write(buf, 0, len);
}
is.close();
zos.closeEntry();
//repeat for file 2
zos.close();
結果是前面的內容被破壞了:WAR只有我剛剛添加的2個文件。有沒有某種附加模式,我不使用或什麼?