0

I want to make some Android Studio app for zipping files. Here is the my code block:

 String input=Environment.getExternalStorageDirectory() +File.separator + "merhaba";
 String output = Environment.getExternalStorageDirectory() + File.separator +"TollCulator";
 zipFolder(input,output);

Here is the my function:

 private static void zipFolder(String inputFolderPath, String outZipPath) {
    try {
        FileOutputStream fos = new FileOutputStream(outZipPath);
        ZipOutputStream zos = new ZipOutputStream(fos);
        File srcFile = new File(inputFolderPath);
        File[] files = srcFile.listFiles();
        Log.d("", "Zip directory: " + srcFile.getName());
        for (int i = 0; i < files.length; i++) {
            Log.d("", "Adding file: " + files[i].getName());
            byte[] buffer = new byte[1024];
            FileInputStream fis = new FileInputStream(files[i]);
            zos.putNextEntry(new ZipEntry(files[i].getName()));
            int length;
            while ((length = fis.read(buffer)) > 0) {
                zos.write(buffer, 0, length);
            }
            zos.closeEntry();
            fis.close();
        }
        zos.close();
    } catch (IOException ioe) {
        Log.e("", ioe.getMessage());
    }
}

Also I am using that in my XML file:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

That is not work for me. I do not have any error in my app. There is no action and there is no zip file in my internal storage.

DiligentKarma
  • 5,198
  • 1
  • 30
  • 33
Ali.A
  • 11
  • 5
  • http://stackoverflow.com/questions/7485114/how-to-zip-and-unzip-the-files – Actiwitty Dec 07 '15 at 23:41
  • Thank you for helping but i am just wondering why my code block doesn't work ? – Ali.A Dec 08 '15 at 19:04
  • I think my function is right because i took it from stackoverflow . But my code block with path maybe wrong . Could you help with that ? – Ali.A Dec 08 '15 at 19:14

1 Answers1

0

Please add:

<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />

to your AndroidManifest

Actiwitty
  • 1,232
  • 2
  • 12
  • 20