Search code examples
javacsvapache-commonsapache-commons-csv

Under what circumstances will the constructor of apache.commons.csv.CSVPrinter throw an IOException?


According to the documentation of org.apache.commons.csv.CSVPrinter, an IOException will be thrown "if the optional header [provided in the second argument] cannot be printed". But what would cause the optional header to be unable to print? Are some strings somehow invalid in the header?


Solution

  • According to the source of org.apache.commons.csv.CSVPrinter, the constructor you link to writes any header comments, and the CSV header (if used), to the output stream given in the parameter out. As this involves writing to the output stream, there is the possibility that an IOException may be thrown.