android编程:怎样读取txt文件
2个回答
展开全部
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("文件不存在!")
}
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("文件不存在!")
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询