I am getting a byte array representing a ZIP file from the JSON response sent by a server, and on the Android side I want to recreate the ZIP from the array.
I am using this code to achieve this but it is not creating a ZIP file in my device storage.
Extract byte array from JSON:
String zipBinary = mJsonObject.getString("zip");
File path for storing zip file:
String unzipLocation = Environment.getExternalStorageDirectory() + "/sample.zip";
Main code:
public CreateZipMultipleFiles(String filePath, byte[] sourceFile) {
try {
ByteArrayOutputStream fout = new ByteArrayOutputStream();
ZipOutputStream zout = new ZipOutputStream(fout);
ZipEntry ze = new ZipEntry(filePath);
ze.setSize(sourceFile.length);
zout.putNextEntry(ze);
zout.write(sourceFile);
zout.closeEntry();
zout.close();
System.out.println("Zip Byte file has been created!");
} catch (IOException ioe) {
System.out.println("IOException :" + ioe);
}
}
How can I achieve this goal?