Mukund
Mukund

Reputation: 1105

Can we delete a particular file in a zip file without unzipping it in android

Suppose I have a zipfile called mine.zip. It contains the text files a.txt, b.txt, c.txt.

I want to delete a.txt from this zipfile without unzipping it.

Also can I copy this b.txt from mine.zip to any other place without unzipping it?

Finally can I copy d.txt from sdcard to mine.zip programatically?

Can this be done android. I have done all the above it with unzipping mine.zip then rezipping it.

but can it be done without unzipping?

Upvotes: 0

Views: 551

Answers (1)

Stan Ning
Stan Ning

Reputation: 31

U can try to find out ur target file from the zip file though ZipEntry. Then

FileInputStream fin = new FileInputStream(zipfile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry entry = null;
while ((entry = zin.getNextEntry()) != null) {
if (entry.getName().equals("aaa.txt")) {
            if (entry.getSize() != 0) {  
                BufferedReader br = new BufferedReader(new InputStreamReader(zipFile.getInputStream(entry)));  
                String line;  
                while ((line = br.readLine()) != null) {  
                    sBuffer.append(line + "\r\n");  
                }  
                sbf.append(sBuffer);  
                br.close();  
            } 
}

Upvotes: 1

Related Questions