Android读取文件
从sd卡中读取一个文件,读取和JAVA类似。
public String loadContentFromSDCard(String fileName) {
String content = null;
try{
File f = new File("sdcard/" + fileName);
int len = (int)f.length();
byte[] buf= new byte[len];
FileInputStream fis = new FileInputStream(f);
fis.read(buf);
fis.close();
content = new String(buf,"UTF-8");
}catch (Exception e) {
Toast.makeText(this, "没有找到文件", Toast.LENGTH_SHORT).show();
}
return content;
}
浙公网安备 33010602011771号