zip4j
zip4j copied to clipboard
Can you make it support with SAF ? I cant extract to android/data without SAF in android 11
after android 11 launched i can't extract the zip using the java.io.file method anymore which is where i am now using the SAF Storage Access Framework, SAF itself uses Uri dan DocumentFile so can you make it work with it, thanks :)
I have sample the code
public void extractZipFile(Uri muri, DocumentFile destDir) throws IOException { ZipEntry entry;
ContentResolver resolver = getContentResolver();
InputStream inputStream = resolver.openInputStream(muri);
try (java.util.zip.ZipInputStream zipInputStream = new java.util.zip.ZipInputStream(inputStream))
{
while ((entry = zipInputStream.getNextEntry()) != null)
{
DocumentFile currentDestDir = destDir;
if (!entry.isDirectory())
{
unzipFile(entry, zipInputStream, currentDestDir);
}
else
{
String finalFolderName = entry.getName().replace("/", "");
currentDestDir = destDir.createDirectory(finalFolderName);
}
}
}
inputStream.close();
}
private void unzipFile(ZipEntry fileEntry, java.util.zip.ZipInputStream zipInputStream, DocumentFile destDir) throws IOException
{
int readLen;
byte[] readBuffer = new byte[BUFFER_SIZE];
DocumentFile destFile = destDir.createFile("*/*", fileEntry.getName());
try (OutputStream outputStream = resolver.openOutputStream(destFile.getUri()))
{
while ((readLen = zipInputStream.read(readBuffer)) != -1)
{
outputStream.write(readBuffer, 0, readLen);
}
}
}
But i have problem with the output Zip, you can see in this link.
Source : https://stackoverflow.com/questions/66202075/how-to-extract-zip-archive-with-subdirectories-using-saf-documentfile
Hello, have you solved this problem, can you tell me how to solve it, can you give me some sample code, thank you