【发布时间】:2020-12-07 07:55:18
【问题描述】:
我正在尝试使用 Eclipse 在我的 Java 类中实现一个 csv 阅读器。我不断收到添加方法的错误“类型列表中的add(Person)不适用于参数(String [])。我做错了什么?
public static List<Person> readPersons(String fileName)
throws FileNotFoundException {
int count = 0;
List<Person[]> content = new ArrayList<>();
try(BufferedReader cv = new BufferedReader(new FileReader(fileName))){
String line = "";
while ((line = cv.readLine()) != null) {
content.add(line.split(","));
}
} catch (FileNotFoundException e) {
}
return content;
}
另外,如何实现这个 FileNotFoundException 扩展器?在程序中是必需的。
【问题讨论】:
-
line.split将返回String的数组,而不是Person的数组。
标签: java arrays eclipse csv oop