我如何在Android Studio项目资产路径? [英] How do I get the Assets path in an Android Studio project?

查看:231
本文介绍了我如何在Android Studio项目资产路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得我失去了一些东西很明显,但我无法传递一个CSV文件 CSVReader ,这需要一个阅读器在其构造。我可以使用 AssetManager.getAssets(),但返回的InputStream ,我无法得到的文件路径在那里,该阅读器的构造需要。我的资产路径是

I feel like I'm missing something obvious, but I'm having trouble passing a CSV file to CSVReader, which takes a Reader in its constructor. I can use AssetManager.getAssets(), but that returns an InputStream and I can't get the file path from there, which the Reader constructor needs. My asset path is

src/main/assets/dbsource/My.csv

我需要进入

CSVReader csvReader = new CSVReader(new FileReader(csvPath));

我只是无法获取路径!谢谢你。

I just can't get the path! Thanks.

推荐答案

这很难哟告诉你什么,你可以不知道做哪些<$​​ C $ C> CSVReader 你使用,但是,假设你使用<一个href=\"https://$c$c.google.com/p/secrets-for-android/source/browse/trunk/src/au/com/byte$c$c/opencsv/CSVReader.java\"相对=nofollow>这个可以方便地使用的InputStreamReader 而不是的FileReader 在这里,因为它接受任何阅读子类。

It's difficult yo tell you what you can do without knowing which CSVReader you're using, but, assuming that you're using this one you can easily use InputStreamReader instead of the FileReader here, because it accepts any Reader subclasses.

也许是更好的方法将是收官的InputStreamReader 的BufferedReader 像这样:

Perhaps the even better way would be to wrap up the InputStreamReader into the BufferedReader like so:

final CSVReader csvReader = new BufferedReader(new InputStreamReader(
    context.getAssets().open("dbsource/My.csv")
));

这篇关于我如何在Android Studio项目资产路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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