CSV 文件导入/读取 - Android
很短的问题:
我已将 .csv 文件放入我的资产文件夹中。我的问题是,我不确定如何读取它并将其内容存储在类似数组的形式中,我可以将其传递给一个函数,然后循环遍历内容。
所以,基本上我想要类似(伪代码)的东西:
VariableArray var[] = new Variable (get the file contents);
performFunction(var[]);
我如何才能完成这个?
Pretty short 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用它来将 InputStream 获取到资产中的文件。
然后你只需要创建一个阅读器并循环遍历文件直到它结束。
You can use this to get an InputStream to your file in assets.
Then you just need to make a reader and loop through the file until the end of it.
我建议您使用 JavaCSV 库来处理 CSV 格式。它可以用很少的代码行完成很多事情。
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.