这个比较简单,直接上代码吧
tvInfo = (TextView) findViewById(R.id.tv_info);PRivate void showInfo() { File file = new File("/mnt/sdcard/Download/11111.txt"); String str = null; try { InputStream is = new FileInputStream(file); InputStreamReader input = new InputStreamReader(is, "UTF-8"); BufferedReader reader = new BufferedReader(input); while ((str = reader.readLine()) != null) { tvInfo.append(str); tvInfo.append("/n"); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }这个最后别忘了加读写sdcard的权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />另外,在刚完成Demo时出现了乱码问题,这个当在记事本保存文件时 选择文件 另存为 就可以看到文件保存编码,选择UTF-8就OK了。

新闻热点
疑难解答