我有一个需要添加两个文件的 WAR 文件。目前,我正在这样做:
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 个文件。是否有某种我没有使用的附加模式或什么?