开发者

CSV File Import/Reading - Android

开发者 https://www.devze.com 2023-03-23 08:43 出处:网络
Pretty shor开发者_如何学Pythont question: I have put a .csv file in my assets folder.My problem is that I\'m unsure how to read it and store its contents in an array-like form that I can pass to a fun

Pretty shor开发者_如何学Pythont question:

I have put a .csv file in my assets folder. My problem is that I'm unsure how to read it and store its contents in an array-like form that I can pass to a function that then loops through the contents.

So, basically I want something like (pseudo code):

VariableArray var[] = new Variable (get the file contents);
performFunction(var[]);

How I can accomplish this?


You can use this to get an InputStream to your file in assets.

InputStream is = getAssets().open(fileName);

Then you just need to make a reader and loop through the file until the end of it.


I suggest you to use the JavaCSV library to deal with CSV formats. There are a lot of things it can accomplish in very few lines of code.

0

精彩评论

暂无评论...
验证码 换一张
取 消