Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中的文件写入失败,java.io.IOException:打开失败:EACCES(权限被拒绝)_Android_File - Fatal编程技术网

android中的文件写入失败,java.io.IOException:打开失败:EACCES(权限被拒绝)

android中的文件写入失败,java.io.IOException:打开失败:EACCES(权限被拒绝),android,file,Android,File,我正在尝试在运行MOTOG的android 4.4.4版本中执行文件写入操作。 我也在清单文件中添加了文件写入权限。但文件写入一直在以各种可能的方式失败 java.io.IOException: open failed: EACCES (Permission denied) 这是我收到的错误消息。下面是我的代码 File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOW

我正在尝试在运行MOTOG的android 4.4.4版本中执行文件写入操作。 我也在清单文件中添加了文件写入权限。但文件写入一直在以各种可能的方式失败

java.io.IOException: open failed: EACCES (Permission denied)
这是我收到的错误消息。下面是我的代码

File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/text.txt");
if (!file.exists()) {
              try {
                file.createNewFile();
                FileWriter fw = new FileWriter(file.getAbsoluteFile());
                BufferedWriter bw = new BufferedWriter(fw);
                bw.write("hi");
                bw.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            }
请帮我解决这个问题。我尽了一切可能。但找不到解决办法

 //check if external storage is available and not read only 
  if (!isExternalStorageAvailable() || isExternalStorageReadOnly()) { 

  }
  else {
   myExternalFile = new File(getExternalFilesDir(filepath), filename);
  }

 private static boolean isExternalStorageReadOnly() { 
  String extStorageState = Environment.getExternalStorageState(); 
  if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(extStorageState)) { 
   return true; 
  } 
  return false; 
 } 

 private static boolean isExternalStorageAvailable() { 
  String extStorageState = Environment.getExternalStorageState(); 
  if (Environment.MEDIA_MOUNTED.equals(extStorageState)) { 
   return true; 
  } 
  return false; 
 }  
试试这个 链接

使用内部存储器

链接

链接:

在mainfestadd outside your application标记中,我在清单中添加了以下权限。但没有运气…在emulator上测试,然后检查sd卡的大小,如果在emulator中尝试过,则增加sd卡的大小。显示了相同的错误消息。moto g没有外部存储,因此尝试在内部存储中写入,并请发布您的mainfestHi All,我已修复了该问题。我忘了将应用程序中的写入权限添加到测试清单中。一旦添加,问题就消失了。谢谢你的建议。
context.getDir("mydir", Context.MODE_PRIVATE); //Creating an internal dir;
File fileWithinMyDir = new File(mydir, "myfile"); //Getting a file within the dir.
FileOutputStream out = new FileOutputStream(fileWithinMyDir); //Use the stream as usual to write into 
String FILENAME = "hello_file";
String string = "hello world!";

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();