Java - Writing strings to a CSV file

前端 未结 7 2138
野趣味
野趣味 2020-11-28 10:45

I am trying to write data to a csv file with java, however when I try opening the produced file with excel I am getting an error saying the file is corrupt. Upon opening the

相关标签:
7条回答
  • 2020-11-28 11:41
        String filepath="/tmp/employee.csv";
        FileWriter sw = new FileWriter(new File(filepath));
        CSVWriter writer = new CSVWriter(sw);
        writer.writeAll(allRows);
    
        String[] header= new String[]{"ErrorMessage"};
        writer.writeNext(header);
    
        List<String[]> errorData = new ArrayList<String[]>();
        for(int i=0;i<1;i++){
            String[] data = new String[]{"ErrorMessage"+i};
            errorData.add(data);
        }
        writer.writeAll(errorData);
    
        writer.close();
    
    0 讨论(0)
提交回复
热议问题