Can't write to sdcard even with permissions set and external storage in MEDIA_MOUNTED state

前端 未结 3 481
轮回少年
轮回少年 2021-01-13 01:17

While trying to write file to sdcard I get java.io.FileNotFoundException: /filename (Read-only file system) exception. Sadly none of the many solutions posted h

3条回答
  •  隐瞒了意图╮
    2021-01-13 01:38

    Try this:

    File file = new File(filePath);
    File parent = file.getParentFile();
    if (!parent.exists() && !parent.mkdirs()) {
          return;
    }
    
    file = new File(Helpers.StripExtension(filePath) + ".blk");
    OutputStream fos = new FileOutputStream(file);
    fos.write(digest.getBytes());
    fos.close();
    

提交回复
热议问题