【问题标题】:Where to give filepath in opencsv project在opencv项目中在哪里给出文件路径
【发布时间】:2013-12-04 15:25:11
【问题描述】:

我是 java 新手,我需要使用 opencsv 项目读取 csv 文件。请指导我在哪个文件中以及我必须将代码放在哪里:

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...");
    }

非常感谢, 问候, 费萨尔

【问题讨论】:

  • 您是否有一些现有的项目要将其集成到其中?如果是这样,请将代码放在那里。否则,编写一个自己的小型 java 类并将代码放在那里。

标签: java csv opencsv


【解决方案1】:

确保“youfile.csv”位于项目的根目录。

变量“nextLine”不需要是数组。

String nextLine;
while ((nextLine = reader.readNext()) != null) {
    System.out.println(nextLine);
}

这将打印出所有的行,因为打印语句在循环中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 2010-11-01
    • 1970-01-01
    • 2014-07-15
    相关资源
    最近更新 更多