/**
* 从assets中读取txt
*/
private void readFromAssets() {
try {
InputStream is = MyApplication.getContext().getAssets().open("qq.txt");
String text = readTextFromSDcard(is);
// textView.setText(text);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 从raw中读取txt
*/
private void readFromRaw() {
try {
InputStream is = MyApplication.getContext().getResources().openRawResource(R.raw.qq);
String text = readTextFromSDcard(is);
XLog.showArgsInfo("text = " + text);
// textView.setText(text);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 按行读取txt
*
* @param is
* @return
* @throws Exception
*/
private String readTextFromSDcard(InputStream is) throws Exception {
InputStreamReader reader = new InputStreamReader(is);
BufferedReader bufferedReader = new BufferedReader(reader);
StringBuffer buffer = new StringBuffer("");
String str;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
buffer.append("\n");
}
return buffer.toString();
}
忘在哪儿看到的了,侵删