Skip to content Skip to sidebar Skip to footer

Unzip File From Server Http

I have a problem to unzip a file received from server. I send a request, and server show me a text with code characters :S With this code i receive a zip from server, but i need th

Solution 1:

If it's a standard zip file, you can use the java.util.zip package.

Here's an example of unzipping an archive that has a folder in it, and writing it to a file.

FileInputStream zipInputStream = new FileInputStream(new File(cacheDir, zipFileName));
FileOutputStream datOutputStream = new FileOutputStream(new File(cacheDir, datFileName));

// unzip and process ZIP file
ZipInputStream zis = new ZipInputStream(zipInputStream);
ZipEntry ze = null;
// loop through archive
while ((ze = zis.getNextEntry()) != null) {
    if (ze.getName().toString().equals("myfolder/myfile.dat")) { // change this to whatever your folder/file is named inside the archive
        while ((bufferLength = zis.read(buffer, 0, 1023)) != -1) {
            datOutputStream.write(buffer, 0, bufferLength);
        }
     }
     zis.closeEntry();
}

Post a Comment for "Unzip File From Server Http"