0

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.

NSouth
  • 5,067
  • 7
  • 48
  • 83
  • Try the answer here: http://stackoverflow.com/questions/11820142/how-to-pass-a-file-path-which-is-in-assets-folder-to-filestring-path – Matter Cat Mar 11 '15 at 06:18

1 Answers1

0

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")
));
aga
  • 27,954
  • 13
  • 86
  • 121