我正在尝试找到一种方法来打开名称仅在运行时确定的资源.
更具体地说,我希望有一个XML引用应用程序apk中的一堆其他XML文件.为了解释,让我们说主要的XML main.xml和其他XML是file1.xml,file2.xml和fileX.xml.我想要的是读取main.xml,提取我想要的XML的名称(fileX.xml例如),然后阅读fileX.xml.我面临的问题是我提取的形式main.xml是一个字符串,我找不到改变它的方法R.raw.nameOfTheFile.
有人有想法吗?
我不想:
我正在尝试打开一个 Json 文件,该文件位于 res 我的文件结构中的 raw 文件夹中
但我尝试过的每种方法都失败了,我只需要字符串,因为我Json Strings已经可以解析了。
这是我的Json读者
public class Parser extends Activity {
public String getStringFromJson(String path) {
StringBuffer sb = new StringBuffer();
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(getAssets().open(path)));
String temp;
while ((temp = br.readLine()) != null)
sb.append(temp);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close(); // stop reading
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
}
Run Code Online (Sandbox Code Playgroud)
它在行中失败:
br = …