使用java替换zip中的特定文件

使用java替换zip中的特定文件,java,file,replace,zip,Java,File,Replace,Zip,我需要替换zip存档中的特定CSS文件。该文件存储在文件夹EPUB/styles/stylesheet.CSS下 这是我的代码,我需要用Java6来做 public static void main(String[] args) throws IOException { File newCss=new File("D:\\test\\css\\stylesheet.css"); ZipOutputStream out = new ZipOutputStream(new File

我需要替换zip存档中的特定CSS文件。该文件存储在文件夹EPUB/styles/stylesheet.CSS下

这是我的代码,我需要用Java6来做

public static void main(String[] args) throws IOException {

    File newCss=new File("D:\\test\\css\\stylesheet.css");
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream
    (new File("D:\\test\\css\\edited\\my_book.epub"),true));
    out.putNextEntry(new ZipEntry("EPUB/styles/stylesheet.css"));

    InputStream in = new FileInputStream(newCss);
    byte[] buf = new byte[4096 * 1024]; 
    int len;
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    out.closeEntry();
    in.close();
    out.close();
    System.out.println("Done Replacing entry");
}
}

但是在执行这段代码时,整个zip只包含我替换的CSS,所有其他内容都丢失了,但zip显示的大小与以前相同,在提取zip时,我只得到我替换的文件。

是否使用Java 7?如果是的话,有一种更好的方法可以做到这一点……我知道在Java7中有一种方法,但需要在Java6中实现