zip4j - Replace specific file inside Zip archive without extracting the whole archive in Java -


i'm trying specific file inside zip archive, extract it, encrypt it, , inside archive replacing origial one.

here's i've tried far..

public static boolean encryptxml(file ziparchive, string key) throws zipexception, ioexception, exception {     zipfile zipfile = new zipfile(ziparchive);     list<fileheader> fileheaderlist = zipfile.getfileheaders();     (fileheader fh : fileheaderlist)     {         if (fh.getfilename().equals("meta-inf/file.xml"))         {             path tempdir = files.createtempdirectory("temp");             zipfile.extractfile(fh, tempdir.tostring());             file xmlfile = new file(tempdir.tofile(), fh.getfilename());              // encrypting xmlfile, ignore part              // here, replace original xmlfile inside ziparchive encrypted 1 <<<<<<<<              return true;         }     }     return false; } 

i stuck @ replacing part of code there anyway can without having extract whole zip archive?

any appreciated, in advance.

not sure if you using different library solution in zt zip following.

ziputil.unpackentry(new file("/tmp/demo.zip"), "foo.txt", new file("foo.txt")); // encrypt foo.txt ziputil.replaceentry(new file("/tmp/demo.zip"), "foo.txt", new file("foo.txt")); 

this unpack foo.txt file , after encrypt can replace previous entry new one.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -