android - 在 android 中写入现有 JSON 文件时遇到问题

标签 android json

我的 Assets 文件夹中有一个现有的 .json 文件。我可以使用 Input steam 成功读取,但是当我想写入此文件时,我无法正确找到它。这是我现在的样子

 try (FileWriter file = 
   new FileWriter(getApplicationContext().getPackageName() +
       "/app/src/main/assets/inventory.json")) {

     file.write(jsonObj.toString());
 }

这是我遇到的错误

01-09 14:43:51.178 21391-21391/edu.wit.senderp.inventorytrack W/System.err: java.io.FileNotFoundException: edu.wit.senderp.inventorytrack/app/src/main/assets/inventory.json (No such file or directory

最佳答案

Assets 文件夹中的文件是只读的。而且您只能通过 AssetManager 访问 Assets 文件.

https://developer.android.com/guide/topics/resources/providing-resources#ResourceTypes

关于android - 在 android 中写入现有 JSON 文件时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54117303/

相关文章:

android - 无法在 Android JellyBean 上构建 hello world 内核模块

Python - 将 x 行 csv 文件写入 json 文件

Python + Scrapy + JSON + XPath : How to scrape JSON data with Scrapy

javascript - 如何在 body 负荷时调用函数

java - 存储数组的值以供将来引用

android - .jar android 库导入 Xamarin 项目

java - tensorflow float32的转换与java对象不兼容

android - 游戏在 Sony Xperia 上崩溃

javascript - Vue.js 排除设置文件被捆绑

json - 按 JSON 数据类型排序 postgres