这是我在项目中常用到的一些工具,为了怕以后找不到故记录于此。
/**
* 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

本文介绍了一个用于操作Android项目中assets目录下文件的工具类AssetsUtils。该工具类提供了读取assets目录下文本文件内容的方法,通过Context和文件路径参数,能够返回文件的字符串内容。在遇到异常时,会返回空字符串并记录错误信息。
336

被折叠的 条评论
为什么被折叠?



