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.
FileInputStreamzipInputStream=newFileInputStream(newFile(cacheDir, zipFileName));
FileOutputStreamdatOutputStream=newFileOutputStream(newFile(cacheDir, datFileName));
// unzip and process ZIP fileZipInputStreamzis=newZipInputStream(zipInputStream);
ZipEntryze=null;
// loop through archivewhile ((ze = zis.getNextEntry()) != null) {
if (ze.getName().toString().equals("myfolder/myfile.dat")) { // change this to whatever your folder/file is named inside the archivewhile ((bufferLength = zis.read(buffer, 0, 1023)) != -1) {
datOutputStream.write(buffer, 0, bufferLength);
}
}
zis.closeEntry();
}
Post a Comment for "Unzip File From Server Http"