在java中读取csv文件从第3行开始
我如何让我的csv文件阅读器将java中的csv文件读取到数组列表中,从第3行开始,但第1行和第2行,每个都被读取到另一个数组列表。例如:
line1 ->数组列表1;
第2行->数组列表2;
line3 - 第 n 行 ->数组列表3
谢谢..
how do i make my csv file reader to read my csv file in java to an arraylist, start from line no.3 but line1 and line2, each of them is read to another arraylist. for example:
line1 -> arraylist1;
line2 -> arraylist2;
line3 - line'n' -> arraylist3
thanks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从有限的细节来看,一个简单的实现将执行以下操作:
我可能会通过单独的方法来处理步骤 2-1、3-1 和 4-1,因为我猜测这 3 个步骤的格式彼此不同。
文件的实际读取可能使用
BufferedReader
能够使用readLine
方法,但这部分可能会根据应用程序的设计而有所不同。该行的处理可以通过将行分割来完成
String.split(",")
并将结果扔进List
中,但它会很脆弱并且容易出错,因此需要一种更好的方法来分解组件,或者使用可以正确处理边缘情况的 CSV 操作库可能是更好的方法。From the limited details, a simple implementation would do the following:
I would probably approach step 2-1, 3-1 and 4-1 by having separate methods, as I am guessing that the formatting for each of those 3 steps are different from each other.
The actual reading of the file may be using a
BufferedReader
which is able to read an entire line at a time by using thereadLine
method, but this part may vary depending on the design of the application.The processing of the line may be accomplished by splitting the line up by
String.split(",")
and tossing the result into aList
, but it would be brittle and error-prone, so a better method of breaking up the components would be needed, or it just may be a better approach to use a CSV manipulation library which can properly handle the edge-cases.你有几个选择。
You have a couple options.