转载自: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;
}