我想将我的数据保存到 CSV 文件中。我正在使用 Scanner 读取 -> CSVWriter 来保存。
我收到错误:不兼容的类型:无法将 List[String] 转换为 String[]。
方法:
private static void insertToFile(String source, String target)
{
List<String> data = new ArrayList<String>();
try{
Scanner sc = new Scanner(new File(source));
while (sc.hasNextLine()) {
data.add(sc.nextLine());
}
sc.close();
}
catch(Exception e){
e.printStackTrace();
}
File resfile = new File(target);
try{
CSVWriter writer = new CSVWriter(new FileWriter(resfile, true));
//BufferedWriter bufferedWriter = new BufferedWriter(writer);
for (String j : data) {
//writer.writeAll(data);//error here
}
writer.close();
}
catch(Exception e){
e.printStackTrace();
}
}