フォルダーの圧縮で構成される単純なAndroidアプリケーションを実行しています。実際に圧縮プロセスが完了し、ファイルが定義された場所に保存されます。しかし、問題は、エミュレーターから圧縮ファイルをプッシュして手動で解凍すると、ファイルが破損することです。どうしたの。手動で解凍するとファイルが破損しますか?
私のフォルダ構造は以下のとおりです
TestPlay1- 2 つのサブディレクトリが含まれます - プレイリストとコンテンツ
ディレクトリ プレイリストには xml ファイル
が含まれます ディレクトリ コンテンツには画像やビデオなどのファイルが含まれます
私のコードは以下のとおりです
String zipFile = "/mnt/sdcard/Testplay1.zip";
byte[] buffer = new byte[1024];
FileOutputStream fos = null;
try {
fos = new FileOutputStream(zipFile);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
ZipOutputStream zos = new ZipOutputStream(fos);
updata = new ArrayList<File>();
contentpath = new File(FOLDER_PATH);
try {
if (contentpath.isDirectory()) {
File[] listFile = contentpath.listFiles();
for (int i = 0; i < listFile.length; i++) {
if (listFile[i].isDirectory()) {
File[] contfile = listFile[i].listFiles();
for (int j = 0; j < contfile.length; j++) {
updata.add(contfile[j]);
FileInputStream fis = new FileInputStream(contfile[j]);
zos.putNextEntry(new ZipEntry(contfile[j].getName()));
int length;
while ((length = fis.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
zos.closeEntry();
// close the InputStream
fis.close();
}
}
}
zos.close();
}
System.out.println("Testplay1 Folder contains=>" + updata);
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}