【发布时间】:2016-12-28 14:30:58
【问题描述】:
我已经写了一个带有数据的 json 文件,我将把它放到 android 中的 recycleview 但我不知道我可以在哪里上传这个文件来访问它到 android 项目中
【问题讨论】:
-
如果您在互联网上需要它,您只需在网络空间提供商中制作并检索它
标签: android arrays json android-studio getjson
我已经写了一个带有数据的 json 文件,我将把它放到 android 中的 recycleview 但我不知道我可以在哪里上传这个文件来访问它到 android 项目中
【问题讨论】:
标签: android arrays json android-studio getjson
可以存储静态json数据here。
【讨论】:
您可以将 JSON 文件存储在您的资产文件夹中......
【讨论】:
void saveStringToFile(String path, String content) {
try {
File newFile = new File(path);
newFile.createNewFile();
FileOutputStream fos = new FileOutputStream(newFile);
fos.write(content.getBytes());
fos.flush();
fos.close();
Constant.logD("File "+ newFile.getName()+ " is saved successfully at "+ newFile.getAbsolutePath());
} catch (Exception e) {
Constant.logE("Unable to save file", e);
}
}
提及移动 SD 卡中的路径,例如 Environment.getExternalStorageDirectory().getAbsolutePath()+"/" + System.currentTimeMillis()+".jpg" 作为路径
【讨论】:
您可以将 json 文件放在 assets 文件夹中,最好的选择是将 json 文件托管在服务器上并在您的项目中使用数据 (API)。
【讨论】:
有两种方法可以做到这一点:
【讨论】: