copyPreCacheToDataFolder(mContext, "mydir"+File.separator+"subdir", "/data/");
public void copyPreCacheToDataFolder(Context context, String oldPath, String newPath) { try { String[] files; files = context.getResources().getAssets().list(oldPath); File dstPath = new File(newPath); if( !dstPath.exists() ) { dstPath.mkdirs(); } for( String file : files ) { String[] subFiles = context.getResources().getAssets().list(oldPath+File.separator+file); if( subFiles.length > 0 ) {//dir if( oldPath.length() == 0 ) { copyPreCacheToDataFolder(context, file, newPath+file+File.separator); } else { copyPreCacheToDataFolder(context, oldPath+File.separator+file, newPath+file+File.separator); } continue; } File outFile = new File(newPath, file); if( outFile.exists() ) { outFile.delete(); } InputStream inStream; if( oldPath.length() != 0 ) { inStream = context.getAssets().open(oldPath+File.separator+file); } else { inStream = context.getAssets().open(file); } OutputStream outStream = new FileOutputStream(outFile); byte[] buf = new byte[1024*2]; int len; while ((len = inStream.read(buf)) > 0) { outStream.write(buf, 0, len); } inStream.close(); outStream.close(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }