标签:
使用场景,在assert文件夹下 有些文本文件,我们需要通过工具类读取出来,然后放到String字符串中,我们该如何操作呢:
直接上代码:
public static String readAssertResource(Context context, String strAssertFileName) { AssetManager assetManager = context.getAssets(); String strResponse = ""; try { InputStream ims = assetManager.open(strAssertFileName); strResponse = getStringFromInputStream(ims); } catch (IOException e) { e.printStackTrace(); } return strResponse; } private static String getStringFromInputStream(InputStream a_is) { BufferedReader br = null; StringBuilder sb = new StringBuilder(); String line; try { br = new BufferedReader(new InputStreamReader(a_is)); while ((line = br.readLine()) != null) { sb.append(line); } } catch (IOException e) { } finally { if (br != null) { try { br.close(); } catch (IOException e) { } } } return sb.toString(); } }
Android读取Assert文件夹下txt文本并变为String的方法
标签:
原文地址:http://www.cnblogs.com/dongweiq/p/4267275.html