我有 csv 文件中从 1980 年开始的每日数据。但我只想读取1985年以来的数据。因为另一个文件中的另一个数据集是从1985年开始的。在Java中如何跳过读取1985年之前的数据?
最佳答案
阅读 opencsv 文档:http://opencsv.sourceforge.net/#how-to-read
读取每一行(来自示例):
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
// nextLine[] is an array of values from the line
System.out.println(nextLine[0] + nextLine[1] + "etc...");
}
转换为int
int one_value=Integer.parseInt(nextLine[i]); // iterate i
然后,获取“年份”列,并将其与 1985 年进行比较
关于java - 如何读取csv文件中的指定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34382745/