標籤:assets sdcard 檔案複製
<pre name="code" class="html">package com.lapel.activity.html;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import android.content.Context;/** * * 將assets檔案夾下的檔案複製到SD卡中 * */public class CopyZipFileToSD {private Context context;String fileName;String filePath;/** * * @param context * @param fileName * fileName(assets檔案夾下壓縮檔):檔案名稱+尾碼 * @param filePath * sd本地路徑 */public CopyZipFileToSD(Context context, String fileName, String filePath) {this.context = context;this.fileName = fileName;this.filePath = filePath;}public void copy() {InputStream inputStream;try {inputStream = context.getResources().getAssets().open(fileName);// assets檔案夾下的檔案File file = new File(filePath);if (!file.exists()) {file.mkdirs();}FileOutputStream fileOutputStream = new FileOutputStream(filePath + "/" + fileName);// 儲存到本地的檔案夾下的檔案byte[] buffer = new byte[1024];int count = 0;while ((count = inputStream.read(buffer)) > 0) {fileOutputStream.write(buffer, 0, count);}fileOutputStream.flush();fileOutputStream.close();inputStream.close();} catch (IOException e) {e.printStackTrace();}}}
將android項目assets檔案夾下的檔案複製到SD卡中