Trying to create a file in Android: open failed: EROFS (Read-only file system)

前端 未结 8 2353
臣服心动
臣服心动 2020-11-27 05:52

This line:

final FileOutputStream outputStream = new FileOutputStream(name);

results in a FileNotFoundException with the messa

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 06:21

    If anyone getting this in unit/instrumentation testing, make sure you call getFilesDir() on the app context, not the test context. i.e. use:

    Context appContext = getInstrumentation().getTargetContext().getApplicationContext();
    

    not

    Context appContext = InstrumentationRegistry.getContext;
    

提交回复
热议问题