简体   繁体   English

哪里将xml文件放在android项目中?

[英]Where to place a xml file in android project?

For my project I am using an xml file to fetch information. 对于我的项目,我正在使用xml文件来获取信息。 I know this can be stored inside assets folders or inside resources/raw folder. 我知道这可以存储在资产文件夹中或资源/原始文件夹中。 My issue is I have to modify the xml dom and write back to the file again as a persistent storage. 我的问题是我必须修改xml dom并再次写回文件作为持久性存储。

I have read that I cant write back to a file in assets folder. 我已经读过我无法写回资产文件夹中的文件。 But no idea regarding the file in resource folder? 但是不知道资源文件夹中的文件吗?

Where can I keep the file for this purpose? 为此,我可以在哪里保存文件? Is storing the file in sdcard the only possible option? 将文件存储在sdcard中是唯一可行的选择吗?

Thanks 谢谢

I would include the file in res/raw and then create a local copy in the file directory for your app. 我会将文件包含在res / raw中,然后在应用程序的文件目录中创建本地副本。 On app init, you can check to see if it exists in the external storage and then if it does not, load it anew from res/raw. 在应用程序初始化上,您可以检查它是否存在于外部存储中,然后如果不存在,请从res / raw重新加载它。

Without going too far into the nitty-gritty, something like this perhaps: 不必太详细了,也许是这样的:

File filesDir = context.getFilesDir();
File xml = new File(filesDir, YOUR_FILE_NAME);
if(xml.exists() {
    /* load data from filesDir */
} else {
    /* load data from res/raw and save to filesDir */
}

Is storing the file in sdcard the only possible option? 将文件存储在sdcard中是唯一可行的选择吗?

Yes, and you can also store the file in internal memory. 是的,您也可以将文件存储在内部存储器中。

You do not have the permission to modify the apk files. 您无权修改apk文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM