android 读取TXT文件

来源:互联网 发布:linux piwik安装详解 编辑:程序博客网 时间:2024/03/28 22:08

转载自:http://blog.csdn.net/barryhappy/article/details/7365271

在android中,若要读取txt文件,则txt文件应该放在rec下的新建文件夹raw下,然后核心代码如下所示:

 /** * function:读取章节目录txt文件 * */public static List<String> getChapterOffsetString(InputStream inputStream) {  List<String> strList = new ArrayList<String>();       InputStreamReader inputStreamReader = null;      try {          inputStreamReader = new InputStreamReader(inputStream, "utf-8");  //gbk    } catch (UnsupportedEncodingException e1) {          e1.printStackTrace();      }      BufferedReader reader = new BufferedReader(inputStreamReader);      StringBuffer sb = new StringBuffer("");      String line;      try {          while ((line = reader.readLine()) != null) {           strList.add(line);           }      } catch (IOException e) {          e.printStackTrace();      }      return strList;  }  


 

原创粉丝点击