android:如何通过BufferedReader访问res/raw目录中的资源

发布于 2024-09-15 10:06:10 字数 116 浏览 6 评论 0原文

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

我该怎么做?

理想情况下我会在它们上安装 BufferedReader 。

谢谢!

i save some ressources in the res/raw directory which i then would like to read with my custom loader.

how can i do this?

ideally i would get a BufferedReader on them.

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

恬淡成诗 2024-09-22 10:06:11

这是常见的方式:

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

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

InputStream rawRes = context.getAssets().open("fileName.extension");
Reader r = new BufferedReader(new InputStreamReader(rawRes, "UTF8"));

This is the common way :

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

You can also put it in the assets folder and access it like that :

InputStream rawRes = context.getAssets().open("fileName.extension");
Reader r = new BufferedReader(new InputStreamReader(rawRes, "UTF8"));
—━☆沉默づ 2024-09-22 10:06:11

getResources().openRawResource() 获取 InputStreamInputStreamReader 获取读取器。 InputStreamReader 具有内置缓冲。

getResources().openRawResource() to get an InputStream. InputStreamReader to get a reader. InputStreamReader has built-in buffering.

乄_柒ぐ汐 2024-09-22 10:06:11

好吧,我刚刚想明白了:

InputStream is = app.getResources().openRawResource(R.raw.ship);
ship = OBJ.load(new BufferedReader(new InputStreamReader(is)));

ok, i just figured it out:

InputStream is = app.getResources().openRawResource(R.raw.ship);
ship = OBJ.load(new BufferedReader(new InputStreamReader(is)));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文