简体   繁体   English

使用openCSV忽略CSV值+将CSV文件中的int值存储在单独的二维数组元素中

[英]Ignoring CSV values with openCSV + Storing int values from CSV file in separate two-dimensional array elements

First part to my question is, if I have a CSV file with 4 numbers on one line separated by a comma, how do I ignore the first two values using openCSV? 我的问题的第一部分是,如果我有一个CSV文件,其中一行上有4个数字,中间用逗号隔开,那么如何使用openCSV忽略前两个值?

Now, consider the following array: 现在,考虑以下数组:

int[][] parsedData = new int [10][10];

and the following line from a CSV file: 以及CSV文件中的以下行:

54, 68, 5, 1

assuming the former is possible (ignoring the first two values on a line in a CSV file), how do I then parse the value '5' into parsedData[0][0] and parse the value '1' into parsedData[0][1]? 假设前者是可能的(忽略CSV文件中一行的前两个值),然后如何将值'5'解析为parsedData [0] [0]并将值'1'解析为parsedData [0] [1]?

I can't find anything in the openCSV documentation that would explain how to do this, nor can I wrap my head around even doing it if there weren't a CSV file to read beforehand. 我在openCSV文档中找不到任何可以解释如何执行此操作的内容,即使没有事先要读取的CSV文件,我也无法做到这一点。

You cannot do that within opencsv. 您无法在opencsv中执行此操作。 You can ignore entire lines with the skiplines (which is normally used when the data has an header) but not part of a line. 您可以使用跳过线忽略整行(通常在数据具有标题时使用),而不是一行的一部分。 You will have to do that yourself programmatically. 您必须自己以编程方式执行此操作。

Take a look at the java System.arraycopy method. 看一看java System.arraycopy方法。 I found an article on stack overflow with a good example . 我找到了有关堆栈溢出的文章,其中有一个很好的例子

Hope that helps. 希望能有所帮助。

:) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM