当前位置: 编程技术>移动开发
android读取sdcard路径下的文件的方法
来源: 互联网 发布时间:2014-10-23
本文导语: 代码如下:// 读取sdcard文件private void sdcardRead(){String fileName = "/sdcard/my_sdcard.txt";// assets下文件//String fileName = "/sdcard/test/my_sdcard_test.txt";// sdcard下子目录文件String ret = "";try {FileInputStream fis = new FileInputStream(fileName);int len = fis.available...
代码如下:
// 读取sdcard文件
private void sdcardRead(){
String fileName = "/sdcard/my_sdcard.txt";// assets下文件
//String fileName = "/sdcard/test/my_sdcard_test.txt";// sdcard下子目录文件
String ret = "";
try {
FileInputStream fis = new FileInputStream(fileName);
int len = fis.available();
byte []buffer = new byte[len];
fis.read(buffer);
ret = EncodingUtils.getString(buffer, "UTF-8");
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
tvTXT.setText(ret);
}