我的用例要求我打开一个txt文件,比如abc.txt,它位于zip存档中,其中包含表单中的键值对
key1=value1
key2=value2
..等等每个键值对在一个新行中.
我必须更改与某个键对应的一个值,并将文本文件放回到存档的新副本中.我怎么在java中这样做?
我到目前为止的尝试:
ZipFile zipFile = new ZipFile("test.zip");
final ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("out.zip"));
for(Enumeration e = zipFile.entries(); e.hasMoreElements(); ) {
ZipEntry entryIn = (ZipEntry) e.nextElement();
if(!entryIn.getName().equalsIgnoreCase("abc.txt")){
zos.putNextEntry(entryIn);
InputStream is = zipFile.getInputStream(entryIn);
byte [] buf = new byte[1024];
int len;
while((len = (is.read(buf))) > 0) {
zos.write(buf, 0, len);
}
}
else{
// I'm not sure what to do here
// Tried