Android 操作安装包中的“assets”目录下的文件工具类

版权声明:本文为luoyong原创文章,转载请注明出处!https://blog.csdn.net/luoyong_blog https://blog.csdn.net/luoyong_blog/article/details/84250706

这是我在项目中常用到的一些工具,为了怕以后找不到故记录于此。

/**
 * 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

猜你喜欢

转载自blog.csdn.net/luoyong_blog/article/details/84250706