I am using apache.commons.csv to create a CSV file. When generating the file ,I want to parse a header with the method .withHeader()
. The values I parse should have quotes like "FILENAME". To do that I want to use an enum class. However I am not quite sure how it works to add quotes around the name. I tested it and with that code:
private enum Header{
FILENAME("\"FILENAME\""),
TEST("\"Test\"");
private final String string;
Header(String string){
this.string = string;
}
}
public void addHeader(File outFile) throws IOException{
CSVPrinter printer = new CSVPrinter(outFile, CSVFormat.DEFAULT.withHeader(Header.class));
}
However when outfile
is created it only contains the header without quotes. Does anyone have an idea how to solve it? I know I use a string array as header but I would like to avoid that, because I have a lot of values an the string would get quite long.