gpt4 book ai didi

java - android中如何从字符串中获取资源

转载 作者:行者123 更新时间:2023-12-02 02:44:29 24 4
gpt4 key购买 nike

我有一个 json 文件,其中包含我想在代码中使用的资源名称,但我不知道如何?Json 文件

{
file1: "file1.xml",
file2: "file2.xml"
...
}

我需要做这样的事情

InputStream f1 = this.getResources().openRawResource(R.raw.file1);
InputStream f2 = this.getResources().openRawResource(R.raw.file2);
InputStream f3 = this.getResources().openRawResource(R.raw.file3);

比在我的代码中进一步使用它

最佳答案

试试这个:

String rawFileName = "file1.xml"
int resId = context.getResources().getIdentifier(rawFileName, "raw", context.getPackageName());
InputStream f1 = this.getResources().openRawResource(resId);`

关于java - android中如何从字符串中获取资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44860304/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com