I'm trying to edit the contents of an odt file using zip4j (I tried using java ZipEntries but I couldn't even delete the entries from the file itself that's why I chose to use a library instead). I can confirm that the file I am trying to overwrite exits I can even read from it and tell when it was created so that part works. Now when I'm trying to edit the odt contents (removing or overwriting) Zip4j throws a ZipException which says: cannot rename modified zip file. What am I doing wrong?
try
{
File temp = new File(f.getParent()+"/tmp/content.xml");
new File(temp.getParent()).mkdirs();
FileUtils.write(temp, "", encoding);
net.lingala.zip4j.ZipFile zf = new net.lingala.zip4j.ZipFile(f.getPath());
ZipParameters p = new ZipParameters();
p.setEncryptionMethod(EncryptionMethod.NONE);
p.setOverrideExistingFilesInZip(true);
p.setFileNameInZip("content.xml");
p.setCompressionMethod(CompressionMethod.DEFLATE);
zf.addFile(temp, p);
}
catch (Exception e)
{
e.printStackTrace();
}