首先把txt文本加载到android虚拟机上面:
用file explorer直接把txt文本放到cdcard的目录上
StringBuffer buffer = new StringBuffer();
try {
FileInputStream fis = new FileInputStream("/sdcard/XXX.txt");
InputStreamReader isr = new InputStreamReader(fis,"GB2312");//文件编码Unicode,UTF-8,ASCII,GB2312,Big5
Reader in = new BufferedReader(isr);
int ch;
while ((ch = in.read()) > -1) {
buffer.append((char)ch);
}
in.close();
tv.setText(buffer.toString()); //buffer.toString())就是读出的内容字符
} catch (IOException e) {
tv.setText("文件不存在!")
}