|
@@ -604,4 +604,40 @@ public class CFileUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static void copyAssetsDirToPhone(Activity activity, String assetsPath, String outPutParentDir){
|
|
|
+ try {
|
|
|
+ String[] fileList = activity.getAssets().list(assetsPath);
|
|
|
+ if(fileList.length>0) {//如果是目录
|
|
|
+ File file=new File(outPutParentDir+ File.separator+assetsPath);
|
|
|
+ file.mkdirs();//如果文件夹不存在,则递归
|
|
|
+ for (String fileName:fileList){
|
|
|
+ assetsPath=assetsPath+File.separator+fileName;
|
|
|
+
|
|
|
+ copyAssetsDirToPhone(activity,assetsPath, outPutParentDir);
|
|
|
+
|
|
|
+ assetsPath=assetsPath.substring(0,assetsPath.lastIndexOf(File.separator));
|
|
|
+ Log.e("oldPath",assetsPath);
|
|
|
+ }
|
|
|
+ } else {//如果是文件
|
|
|
+ InputStream inputStream=activity.getAssets().open(assetsPath);
|
|
|
+ File file=new File(outPutParentDir+ File.separator+assetsPath);
|
|
|
+ Log.i("copyAssets2Phone","file:"+file);
|
|
|
+ if(!file.exists() || file.length()==0) {
|
|
|
+ FileOutputStream fos=new FileOutputStream(file);
|
|
|
+ int len=-1;
|
|
|
+ byte[] buffer=new byte[1024];
|
|
|
+ while ((len=inputStream.read(buffer))!=-1){
|
|
|
+ fos.write(buffer,0,len);
|
|
|
+ }
|
|
|
+ fos.flush();
|
|
|
+ inputStream.close();
|
|
|
+ fos.close();
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|