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.