没有得到的包名 [英] Not getting the package name

查看:121
本文介绍了没有得到的包名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找回从原始文件夹中的动态code中的文件,如下

I'm trying to retrieve the file from the raw folder dynamically the code as below

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){}

如果我直接在写什么中输入包的名称,它显示错误。请给一些关于它的主意。

If I type the package name directly in the "what to write" section, it showing the error. Please give some idea about it.

推荐答案

假设你想要动态检索原始资源的ID,下面的code段将是有益的:

Assuming that you want to retrieve the id of a raw resource dynamically, the following code snippet would be useful:

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

和您的DataInputStream以对象应该被这样构成:

and your DataInputStream object should be constructed thus:

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

这篇关于没有得到的包名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆