将json对象添加到资产上的json数组

问题描述 投票:-1回答:1

我正在尝试将json对象附加到我的json数组中。所以我认为它得到了它。但我正在尝试获取我的json文件上的文件文件位置。它在我的资产文件夹中。这是代码和错误。如何获取资产文件夹中的文件位置?

File fileJson = new File(getApplicationContext().getExternalFilesDir("/app"), "products.json");

03-04 15:26:33.609 6784-6784/com.elishanarida.json W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.elishanarida.json/files/app/products.json (No such file or directory)
android json
1个回答
0
投票

资产文件只读,不能写,你可以通过AssetsManager获取资产文件.Assets文件不同于ExternalFilesDir,它是在你的apk而不是SD memery.So new File(getApplicationContext().getExternalFilesDir("/app"), "products.json");is错误。

© www.soinside.com 2019 - 2024. All rights reserved.