问题
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
I need to get this into
CSVReader csvReader = new CSVReader(new FileReader(csvPath));
I just can't get the path! Thanks.
回答1:
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.
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")
));
来源:https://stackoverflow.com/questions/28979778/how-do-i-get-the-assets-path-in-an-android-studio-project