可以结合浏览文件的代码让用户可以选文件
/**
* 判断sd卡是否存在 Environment.getExternalStorageState() 得到sd卡当前的状态
*
* getExternalStorageState() returns MEDIA_MOUNTED if the media is
* present and mounted at its mount point with read/write access. 如果返回
* MEDIA_MOUNTED表示外部存储设备存在。并且有读写的权限(因为sd卡有写保护 如果写保护关闭也是没有权限读写的)
*/
String fileNameString = "espeak-data/example.txt";
int info;
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
if ("".equals(fileNameString)) {
info = R.string.sdNotExit;
} else {
FileInputStream fileInputStream = null;
try {
/**
* Environment.getExternalStorageDirectory(); 得到外存储设备的路径
*
*/
File file = new File(Environment.getExternalStorageDirectory(), fileNameString);
fileInputStream = new FileInputStream(file);
String contentString = DataManager.readDate(fileInputStream);
mEditText.setText(contentString);
} catch (Exception e) {
info = R.string.infor;
} finally {
try {
if (fileInputStream != null) {
fileInputStream.close();
}
} catch (IOException e) {
info = R.string.infor;
}
}
}
} else {
info = R.string.infor;
}