我正在尝试使用OpenCSV
API将2D数组写入CSV文件。我有以下方法:
Path path = Paths.get("/Users/Home/");
String[][] d = new String[10][10];
CSVWriter writer =
new CSVWriter(Files.newBufferedWriter(path.resolve("data.csv"),StandardOpenOption.CREATE_NEW));
writer.writeNext(Arrays.asList(d)); // Does not work!
writer.close();
事实上,writer.writeNext(Arrays.asList(d))
不起作用,我陷入了困境。任何帮助表示赞赏。
答案 0 :(得分:0)
来自docs of CSVWriter writeNext
期望一个String数组。你可以按如下方式迭代
for (int i=0; i < d.length; i++) {
writer.writeNext(d[i]);
}