I am not an Android developer, therefore, we consider this code only as TIP
class ZipCompress { public static void main(String[] args) throws IOException { String dir = "d:\\My folder\\";
Edit
I'm not sure what you want to do here.
if (_files.get(i).getAbsolutePath().contains(".")) entry = new ZipEntry(_files .get(i) .getAbsolutePath() .substring( _files.get(i).getAbsolutePath() .lastIndexOf("/") + 1));
From what I see, it removes the path to the file, leaving only the file name (something like _files.get(i).getName() ). If this is true, that is why you do not have the folder structure in your zip file. You say that the zip entry should only be that file name without any folders.
So, if you want the zip file to contain part of the path from /my/full/path/to/folder/temp/folder1/file1 as temp/folder1/file1 just delete the unnecessary part of this path when creating the ZipEntry, for example
String dir = "/my/full/path/to/folder/"; for (int i = 0; i < _files.size(); i++) { ... if (_files.get(i).getAbsolutePath().contains(".")) { entry = new ZipEntry(_files .get(i).getAbsolutePath().replace(dir, "")); ...
source share