アプリケーションにいくつかのファイルを追加する必要があり、アプリケーションのインストール後にこのファイルを SD カードに解凍する必要があります。Androidでも可能ですか?どうすればそれを行うことができますか?
1 に答える
2
ファイルを resources/raw ディレクトリに追加します。アプリケーションの実行時に、ターゲット ファイルの存在を確認できます。存在しない場合は、解凍して SD カードに書き込みます。
File dest = Environment.getExternalStorageDirectory();
InputStream in = context.getResources().openRawResource(R.raw.file);
// Used the File-constructor
OutputStream out = new FileOutputStream(new File(dest, "file.zip"));
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
try {
// A little more explicit
while ( (len = in.read(buf, 0, buf.length)) != -1){
out.write(buf, 0, len);
}
} finally {
// Ensure the Streams are closed:
in.close();
out.close();
}
于 2012-09-02T17:19:30.953 に答える