android - 在android中读取文件-文件权限被拒绝

标签 android filesystems

我想从外部存储读取文件。我将 Eclipse DDMS 中的文件上传到 storage/sdcard(下图)。但是每当我尝试阅读时,我都会收到权限被拒绝的错误。我的文件权限有问题吗?或者我需要在 list 文件中添加任何东西(我现在没有写任何东西)?

任何帮助将不胜感激。

Folder Tree

代码:

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/

相关文章:

android - 将 cordova 应用程序部署到连接的设备时无法部署到设备

filesystems - 什么是范围(在 FS 中)?

python - 如何通过 Python 查找与 Windows 文件关联的图标?

linux - 为什么文件不能被inode操作?

c++ - 使用 boost::filesystem::path 获取绝对路径

Android Gradle DexException : Multiple dex files define Lorg/hamcrest/Description

java - Popup设置为wrap_content后如何获取其高度?

java - 无法访问自定义 View 类中的方法

android - Jetpack Compose 中的 @Stable 和 @Immutable 注解是什么意思?

Windows NTFS 和区分大小写