首页 > 解决方案 > java.io.IOException:只读文件系统,在android虚拟设备上测试时

问题描述

当我在 android studio 上测试 android 虚拟设备java.io.IOException: Read-only file system时,尝试写入文件时出现错误。我想这是因为程序正在尝试将文件创建/写入到测试文件上的虚拟 android 设备上,但话虽如此,我不知道如何将文件保存到“本地”文件系统,比如“C:_tmp_output.json”。

我还添加了使用权限android.permission.READ_EXTERNAL_STORAGE行,但没有像我预期的那样工作。有人会帮我解决这个问题吗?谢谢你。

    File test = new File("C:\\_tmp\\_output.json");
    test.createNewFile() ;
    FileWriter file = new FileWriter("C:\\_tmp\\_output.json");
    file.write(String.valueOf("foobar"));

标签: javaandroidandroid-studio

解决方案


推荐阅读