java.io.IOException: Read-only file system

后端 未结 4 1731
一生所求
一生所求 2021-01-06 06:32
File mediaDir = new File(\"media\");
if (!mediaDir.exists()){
    mediaDir.createNewFile();
    mediaDir.mkdir();

}

File f = new File(\"/data/data/com.test.image/f         


        
相关标签:
4条回答
  • 2021-01-06 06:57

    Use mediaDir.mkdirs(); instead of mediaDir.mkdir(); also you must require WRITE_EXTERNAL_STORAGE permission

    0 讨论(0)
  • 2021-01-06 07:00

    Guess /data/data is not external storage. You need to have root permission in order to write to the /data directory. Refer Data directory has no read/write permission in Android

    0 讨论(0)
  • 2021-01-06 07:10

    You are creating file in Android system's root directory for which no application is allowed to.

    To create directory specific to your application, use getDir(String dirName, int mode) instead of new File("media"). By calling only, you can create media directory and use it.

    No need to do so many stuffs what you are doing in your above code. Also no need to give any permission in manifest too.

    0 讨论(0)
  • 2021-01-06 07:10

    You can try something like the following to make a folder in an Activity

    this.getDir("folder_name", Context.MODE_PRIVATE);
    

    source

    0 讨论(0)
提交回复
热议问题