2

我在 res/raw 目录中保存了一些资源,然后我想用我的自定义加载器读取这些资源。

我怎样才能做到这一点?

理想情况下,我会在他们身上得到一个 BufferedReader。

谢谢!

4

3 回答 3

7

这是常见的方式:

InputStream rawRes = getResources().openRawResource(yourResourceName);
Reader r = new InputStreamReader(rawRes);
//no need of a buffer, it already has an [internal one][1].

您也可以将它放在 assets 文件夹中并像这样访问它:

InputStream rawRes = context.getAssets().open("fileName.extension");
Reader r = new BufferedReader(new InputStreamReader(rawRes, "UTF8"));
于 2010-08-19T10:42:29.930 回答
3

getResources().openRawResource()得到一个InputStream. InputStreamReader得到一个读者。InputStreamReader有内置缓冲。

于 2010-08-19T10:39:39.917 回答
1

好的,我刚刚想通了:

InputStream is = app.getResources().openRawResource(R.raw.ship);
ship = OBJ.load(new BufferedReader(new InputStreamReader(is)));
于 2010-08-19T11:51:11.557 回答