我想制作一些用于压缩文件的Android Studio应用。这是我的代码块:
String input=Environment.getExternalStorageDirectory() +File.separator + "merhaba";
String output = Environment.getExternalStorageDirectory() + File.separator +"TollCulator";
zipFolder(input,output);
这是我的功能:
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());
}
}
我也在我的XML文件中使用它:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
这对我不起作用。我的应用程序中没有任何错误。没有动作,我的内部存储器中没有zip文件。
答案 0 :(得分:0)
请添加:
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
到AndroidManifest