标签:
Android过程:InputStream-InputStremRreader-BufferedReader-String;
其中 InputStream inputStream=getResources().openRawResource(R.raw.abc);//abc 为 在res/raw文件下的txt文件
Java读取外部txt文件
InputStreamReader read =
new
InputStreamReader(
new
FileInputStream(file),encoding);
//考虑到编码格式
public String getString( InputStream inputStream) {
InputStreamReader inputStreamReader = null;
try {
inputStreamReader = new InputStreamReader(inputStream, "gbk");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
BufferedReader reader = new BufferedReader(inputStreamReader);
StringBuffer sb = new StringBuffer("");
String line;
try {
while ((line = reader.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
sb.close;
return sb.toString();
}
标签:
原文地址:http://www.cnblogs.com/zhuman/p/5427046.html