欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java导出csv文件

程序员文章站 2022-05-26 19:14:02
...
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import au.com.bytecode.opencsv.CSVWriter;


public class CsvDemo {
    
    public static void main(String[] args) throws IOException {
        
        final String[] header = new String[]{"name", "sex", "age"};
        final String[][] data = new String[][]{header, {"日日", "F", "22"}, {"Tom", "M", "25"}, {"Lily", "F", "19"}};

         File tempFile = new File("./Output.csv");        

         CSVWriter writer = new CSVWriter(new FileWriter(tempFile));
        for (int i = 0; i < data.length; i++) {
             writer.writeNext(data[i]);
         }
         writer.close();
         
     }
}

 

相关标签: Java Excel F#