Android 操作安裝包中的“assets”目錄下的檔案工具類
阿新 • • 發佈:2018-11-26
這是我在專案中常用到的一些工具,為了怕以後找不到故記錄於此。
/** * Created by LY on 2015/6/12. * 操作安裝包中的“assets”目錄下的檔案 */ public class AssetsUtils { /** * read file content * * @param context the context * @param assetPath the asset path * @return String string */ public static String readText(Context context, String assetPath) { // LogUtil.d("read assets file as text: " , assetPath); try { return ConvertUtils.toString(context.getAssets().open(assetPath)); } catch (Exception e) { // LogUtil.e("error",e); return ""; } } }
程式碼中用的ConvertUtils