アンドロイドアセットにzipファイルを保存します。どのようにしてアンドロイドの内部ストレージにファイルを抽出しますか?私はファイルを取得する方法を知っているが、私はそれを抽出する方法を知らない。 DAndroidアセットのファイルを解凍する
答えて
このコードはあなたを助けます....オブジェクトを作成している間に、抽出されたファイルをこのクラスに保存する場所を渡してください...そして解凍メソッドを呼び出してください...
Sreedev Rソリューション、 に基づいてpublic class Decompress {
private String zip;
private String loc;
public Decompress(String zipFile, String location) {
zip = zipFile;
loc = location;
dirChecker("");
}
public void unzip() {
try {
FileInputStream fin = new FileInputStream(zip);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v("Decompress", "Unzipping " + ze.getName());
if(ze.isDirectory()) {
dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(loc + ze.getName());
for (int c = zin.read(); c != -1; c = zin.read()) {
fout.write(c);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
} catch(Exception e) {
Log.e("Decompress", "unzip", e);
}
}
private void dirChecker(String dir) {
File f = new File(_location + dir);
if(!f.isDirectory()) {
f.mkdirs();
}
}
}
ありがとうございます。それは働いた:D – kyuu
私がupvotingによって私をサポートしてくれたなら、あなたを助けてくれるよ... –
こんにちは、私は20MBのファイルを解凍しようとしていて、それは長い時間を取っている.. –
たぶん、あなたはからのInputStreamとの組み合わせでのFileOutputStreamを使用してみてください。これは..助けるため
Util zip ;
zip = new Util();
zip.copyFileFromAsset(this, "myfile.zip", getExternalStorage()+
"/android/data/edu.binus.profile/");
おかげで私のコードですZIPファイル。パッケージファイルでは、これはうまくいくはずです。
this questionから@wordyを引用する:ProGuardのに問題があるかもしれないよう
PackageManager pm = context.getPackageManager();
String apkFile = pm.getApplicationInfo(context.getPackageName(), 0).sourceDir;
ZipFile zipFile = new ZipFile(apkFile);
ZipEntry entry = zipFile.getEntry("assets/FILENAME");
myInput = zipFile.getInputStream(entry);
myOutput = new FileOutputStream(file);
byte[] buffer = new byte[1024*4];
int length;
int total = 0;
int counter = 1;
while ((length = myInput.read(buffer)) > 0) {
total += length;
counter++;
if (counter % 32 == 0) {
publishProgress(total);
}
myOutput.write(buffer, 0, length);
}
は見えますが、うまくいけば、コードサンプルは、あなたのために働きます。
暗号化などの追加機能を提供するzip4j外部ライブラリを利用することもできます。また、パスを提供する特定の場所にファイルを抽出する機能も備えています。
私は、資産と使用バッファからファイルを読み込むためのオプションを追加しました:
package com.pixoneye.api.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import android.content.Context;
import android.util.Log;
public class Decompress {
private static final int BUFFER_SIZE = 1024 * 10;
private static final String TAG = "Decompress";
public static void unzipFromAssets(Context context, String zipFile, String destination) {
try {
if (destination == null || destination.length() == 0)
destination = context.getFilesDir().getAbsolutePath();
InputStream stream = context.getAssets().open(zipFile);
unzip(stream, destination);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void unzip(String zipFile, String location) {
try {
FileInputStream fin = new FileInputStream(zipFile);
unzip(fin, location);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public static void unzip(InputStream stream, String destination) {
dirChecker(destination, "");
byte[] buffer = new byte[BUFFER_SIZE];
try {
ZipInputStream zin = new ZipInputStream(stream);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v(TAG, "Unzipping " + ze.getName());
if (ze.isDirectory()) {
dirChecker(destination, ze.getName());
} else {
File f = new File(destination + ze.getName());
if (!f.exists()) {
FileOutputStream fout = new FileOutputStream(destination + ze.getName());
int count;
while ((count = zin.read(buffer)) != -1) {
fout.write(buffer, 0, count);
}
zin.closeEntry();
fout.close();
}
}
}
zin.close();
} catch (Exception e) {
Log.e(TAG, "unzip", e);
}
}
private static void dirChecker(String destination, String dir) {
File f = new File(destination + dir);
if (!f.isDirectory()) {
boolean success = f.mkdirs();
if (!success) {
Log.w(TAG, "Failed to create folder " + f.getName());
}
}
}
}
- 1. AndroidでRarファイルを解凍する
- 2. log.gzファイルを解凍する
- 3. tar.gzファイルを解凍する
- 4. 解凍gzipファイル
- 5. 解凍ファイル
- 6. 解凍ファイル
- 7. Matlabの(解凍ファイル)
- 8. Powershellで解凍(解凍)せずに* .zipファイル内のファイルを置換する
- 9. Android evn内の.7zファイルの解凍に関する問題
- 10. Android:暗号化されたzipファイルを解凍する方法
- 11. Cで4GBのファイルを解凍する#
- 12. ビッグエンディアンのxzファイルを解凍する
- 13. HDFSのファイルを解凍する
- 14. 私は(解凍)javascripteでzipファイルのバイナリデータを解凍したい
- 15. Linuxでこのマルチパートのzipファイルを解凍/解凍する方法は?
- 16. ファイルの内容の解凍
- 17. デバイス上のファイルの解凍
- 18. が.gzファイルを解凍
- 19. UWP 7Zファイルの解凍
- 20. モノトゥッチ - 解凍ファイルのICSharpCode.SharpZipLib
- 21. Unicodeエラーの解凍ファイル
- 22. バッチで.gzファイルの解凍
- 23. サードパーティ製のvb.netなしでファイルを解凍/解凍する方法
- 24. zipファイルを解凍するWindows API?
- 25. ループ中にファイルを解凍する
- 26. ZIpFileでファイルを解凍する
- 27. ファイルを自動的に解凍する
- 28. ファイルを解凍する方法
- 29. フォルダとファイルを圧縮/解凍する
- 30. gzippedファイルを解凍する方法
uを取得しているかの問題?どこで内部ストレージまたは外部ストレージ内のzipファイルを抽出したいですか? –
あなたは、アセットがAndroidツールによって圧縮されていることはどうにか知っています。だからあなたはそこにZIPファイルを置くことによって二重の圧縮をしている。ファイルをまとめてバンドルする場合は、次のようにします。tarを使用しますか?あなたは圧縮せずにジッパーをしますか?バンドルが目的でない場合は、ファイルをそのまま置いて、Androidツールチェーンに圧縮を残してください。 – akauppi