0

ファイルを圧縮するための 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 ファイルはありません。

4

1 に答える 1