操作zip压缩文件时,要想加减修改其中的zipEntry内容,不改变整个大压缩文件有没有办法?

cql0007 2005-09-15 05:32:56
用JAVA弄的一个编辑的东东,文件都放在一个大的ZIP包中

我想对其中的某个文件内容进行修改,或删除怎么如何实现?添加的已经找到方法了。

搜索了一下说现在API不支持修改和删除,那只有将它全部解出来再往另一文件里写这样来操作吗??

谢谢!

惭愧,无分可加了
...全文
585 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
usxue 2005-10-30
  • 打赏
  • 举报
回复
要用到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();
}
}
}
cql0007 2005-09-16
  • 打赏
  • 举报
回复
看了一上午的truezip,看它的文档介绍和网站上介绍,它说确实是可以从ZIP文件里删除和增加文件的内容的。


不过没看到它这方面的应用,看了它的API文档,只有上十来个类的,东西不多。我每个类都看了看,可是没发现相关的增加删除的方法啊,不知该如何实际操作。

在网上搜索truezip,中文的没一个资料,英文的也一般都是简介一下,最后的链接还是链到truezip网站了。

不知gtlang78() 或哪位老兄研究过这个包没有?
非常感谢!
cql0007 2005-09-16
  • 打赏
  • 举报
回复
TO gtlang78() ( )

找了一下居然没找到下载的地方,API和exsample都没看到。

有个下载链接让我跑到了trueMirror那里去了,把那个trueMirror下载下来,看了一下好象不太明白它那东东
cql0007 2005-09-16
  • 打赏
  • 举报
回复
.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文太差了,要慢慢吃力的看
benu 2005-09-16
  • 打赏
  • 举报
回复
我也遇到过这个问题,找了半天方法最后还是用解压-》处理-》再压缩的方法做的,

关注楼主的问题中
gtlang78 2005-09-15
  • 打赏
  • 举报
回复
试试这个行不行
https://truezip.dev.java.net/
interhanchi 2005-09-15
  • 打赏
  • 举报
回复
学习!
cql0007 2005-09-15
  • 打赏
  • 举报
回复
我做的压缩包里放的是地图文件,几十个文件几十M的东东,这样几个文件导来导去麻烦啊,有没有高手有好的解决方法了.

我也是用1.4,1.5没试过
majy 2005-09-15
  • 打赏
  • 举报
回复
是的,只有这个办法了,我也郁闷好好多年了,它就是不支持啊,JDK1.5偶就不知道了,我用1.4

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧