gpt4 book ai didi

android - 没有得到包名

转载 作者:行者123 更新时间:2023-11-29 21:56:17 30 4
gpt4 key购买 nike

我正在尝试使用如下代码动态地从原始文件夹中检索文件

try{
DataInputStream dataIO= new DataInputStream(getResources().getIdentifier("raw/"+chapter, null ,<what to write>);
String strLine= null;
while((strLine = dataIO.readLine())!=null){
buffer.append(strLine);
buffer.append("\n");
}
dataIO.close();
}catch(Exception e){}

如果我直接在“what to write”部分输入包名,它会显示错误。请给出一些想法。

最佳答案

假设您想动态检索原始资源的 ID,下面的代码 fragment 会很有用:

int id = getResources().getIdentifier(chapter, "raw", getPackageName());

您的 DataInputStream 对象应该这样构造:

DataInputStream dataIO= new DataInputStream(getResources().openRawResource(id));

关于android - 没有得到包名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13153733/

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