Android Resource工具类源码分享
时间:2014-04-15 10:09 来源: 我爱IT技术网 作者:微风
Android Resource工具类源码分享
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import cn.trinea.android.common.util.StringUtils; import android.content.Context; public class ResourceUtils { public static String geFileFromAssets(Context context, String fileName) { if (context == null || StringUtils.isEmpty(fileName)) { return null; } StringBuilder s = new StringBuilder(""); try { InputStreamReader in = new InputStreamReader(context.getResources().getAssets().open(fileName)); BufferedReader br = new BufferedReader(in); String line; while ((line = br.readLine()) != null) { s.append(line); } return s.toString(); } catch (IOException e) { e.printStackTrace(); return null; } } public static String geFileFromRaw(Context context, int resId) { if (context == null) { return null; } StringBuilder s = new StringBuilder(); try { InputStreamReader in = new InputStreamReader(context.getResources().openRawResource(resId)); BufferedReader br = new BufferedReader(in); String line; while ((line = br.readLine()) != null) { s.append(line); } return s.toString(); } catch (IOException e) { e.printStackTrace(); return null; } } }
本文来源 我爱IT技术网 http://www.52ij.com/jishu/5040.html 转载请保留链接。
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
