把android assets文件夹内的文件存储到sd卡中
16lz
2021-01-23
原文: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(); } }
更多相关文章
- android使用sharedPreferences()方法读写文件操作
- 在系统里设置文件默认打开APP
- Android实现屏幕截图并保存截图到指定文件
- Android 中读取SD卡文件时抛出NullPointerException错误解决办法
- Android media媒体库分析之:分类别统计媒体文件大小
- android文件处理
- Android复制Assets目录下的文件到指定目录