























公用
public static boolean CopyAssetsFile(Context context,String assetFile, String outFile) throws Exception { FileOutputStream fo = new FileOutputStream(outFile); InputStream assetsDB = context.getAssets().open(assetFile); byte[] buffer = new byte[512]; int length; while ((length = assetsDB.read(buffer)) > 0) { fo.write(buffer, 0, length); } fo.flush(); fo.close(); assetsDB.close(); return true; }
示例
try { String apkName = "test.apk"; String apkDir = "/data/data/com.xxx.demo/apps"; File apkDirPath = new File(apkDir); if (!apkDirPath.exists()) { apkDirPath.mkdir(); } String apkUrl = apkDir + "/" + apkName; File apkFile = new File(apkUrl); if (apkFile.exists()) { apkFile.delete(); } CopyAssetsFile(this, apkName, apkUrl); } catch (Exception ex) { Log.e("Error", ex.getMessage()); }
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。