用JAVA弄的一个编辑的东东,文件都放在一个大的ZIP包中我想对其中的某个文件内容进行修改,或删除怎么如何实现?添加的已经找到方法了。搜索了一下说现在API不支持修改和删除,那只有将它全部解出来再往另一文件里写这样来操作吗??谢谢!惭愧,无分可加了

解决方案 »

  1.   

    是的,只有这个办法了,我也郁闷好好多年了,它就是不支持啊,JDK1.5偶就不知道了,我用1.4
      

  2.   

    试试这个行不行
    https://truezip.dev.java.net/
      

  3.   

    .You need to use an additional API (the package java.util.zip) if your application needs to support ZIP compatible files in addition to ordinary files and directories, thereby significantly inflating your code and adding unnecessary complexity (which adds bugs, bugs, and even more bugs). .You can either read or completely write ZIP compatible files, but you cannot just update individual entries. .The classes do not support the concept of a directory, which you may want to create, modify, list or delete. 
    The TrueZIP Library has been developed to overcome these limitations/disadvantages.-----------------
    大概看了一下,看到这些的时候好值得期待,似乎确实能解决我这个问题了,先研究研究看看汗,E文太差了,要慢慢吃力的看
      

  4.   

    TO  gtlang78() ( ) 找了一下居然没找到下载的地方,API和exsample都没看到。有个下载链接让我跑到了trueMirror那里去了,把那个trueMirror下载下来,看了一下好象不太明白它那东东
      

  5.   

    看了一上午的truezip,看它的文档介绍和网站上介绍,它说确实是可以从ZIP文件里删除和增加文件的内容的。
    不过没看到它这方面的应用,看了它的API文档,只有上十来个类的,东西不多。我每个类都看了看,可是没发现相关的增加删除的方法啊,不知该如何实际操作。在网上搜索truezip,中文的没一个资料,英文的也一般都是简介一下,最后的链接还是链到truezip网站了。不知gtlang78() 或哪位老兄研究过这个包没有?
    非常感谢!
      

  6.   

    要用到truezip.jar:import de.schlichtherle.io.*;import java.io.PrintStream;public class Aaaa {
        public static void main(String[] args) throws Exception {
            try {
             //可以在zip文件中嵌套zip文件。下面最后生成outer.zip文件。
                FileOutputStream fos = new FileOutputStream("outer.zip/inner.zip/output.txt");
                
                PrintStream ps = new PrintStream(fos);
                ps.println("Creating nested ZIP files is really a no-brainer!");
                ps.println(2323);
                fos.close();
                ps.close();
            }
            catch (Exception e) {
             e.printStackTrace();
            }
            finally {
                File.update();
            }
            
            try {
                //outer.zip文件中的inner.zip,是作为一个Directory而不是一个File。
                File file = new File("outer.zip/inner.zip");
                if(file.isFile())
                 file.delete();
                else if(file.isDirectory())
                 file.deleteAll();
            }catch(Exception e) {
             e.printStackTrace();
            }
        }
    }