您的位置:首页 > 移动开发 > Android开发

把android assets文件夹内的文件存储到sd卡中

2015-04-23 13:08 591 查看
原文:http://mobile.51cto.com/aprogram-387591.htm

/**
* 存资源在data中
* @param ctxDealFile applicationContext
* @param path
*/
public void deepFile(Context ctxDealFile, String path) {
try {
String str[] = ctxDealFile.getAssets().list(path);
if (str.length > 0) {//如果是目录
File file = new File(ctxDealFile.getFilesDir().getAbsolutePath()+"/" + path);
if (file.exists()) {

}else {
file.mkdirs();
for (String string : str) {
path = path + "/" + string;
deepFile(ctxDealFile, path);
path = path.substring(0, path.lastIndexOf('/'));
}
}

} else {//如果是文件
InputStream is = ctxDealFile.getAssets().open(path);
FileOutputStream fos = new FileOutputStream(new File(ctxDealFile.getFilesDir().getAbsolutePath()+"/"
+ path));
byte[] buffer = new byte[1024];
int count = 0;
while (true) {
count++;
int len = is.read(buffer);
if (len == -1) {
break;
}
fos.write(buffer, 0, len);
}
is.close();
fos.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐