我想从外部存储读取文件。我将 Eclipse DDMS 中的文件上传到 storage/sdcard(下图)。但是每当我尝试阅读时,我都会收到权限被拒绝的错误。我的文件权限有问题吗?或者我需要在 list 文件中添加任何东西(我现在没有写任何东西)?
任何帮助将不胜感激。
代码:
public void extimport(View v){
EditText xedittxt = (EditText) findViewById(R.id.frmexttxt);
String xedit = xedittxt.getText().toString();
xedit = xedit.trim();
File file;
file = new File(xedit);
StringBuilder text = new StringBuilder();
Log.d("fcheck",""+xedit);
try {
BufferedReader br = new BufferedReader(new FileReader(file)); //THIS LINE THROWS ERROR
Log.d("fcheck","f3"); //This line never got printed
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
br.close();
resultView = (TextView) findViewById(R.id.header);
resultView.setText(text);
}
catch (IOException e) {
Log.d("File open error",""+e);
Toast.makeText(getApplicationContext(), "Error opening the file.", Toast.LENGTH_SHORT).show();
}
}
LogCat:
11-19 00:21:54.252: D/fcheck(5885): /storage/sdcard/mylibman.csv
11-19 00:21:54.272: D/File open error(5885): java.io.FileNotFoundException: /storage/sdcard/mylibman.csv: open failed: EACCES (Permission denied)
最佳答案
确保您已在 list 文件中添加了读取外部存储的权限。
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
关于android - 在android中读取文件-文件权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20063957/