I am using opencsv 3.0 version. For some reason it is not writing out the records to the CSV file. It worked fine with version 2.3. However, I wanted to use the CSVIterator class. Any help is appreciated.
public void writeGradesIntoFile(GradeReport gradeReport,String outputFileName)
{
File outputCSVFile = null;
CSVWriter csvFileWriter = null;
String[] lastRecord = null;
try {
outputCSVFile = new File(outputFileName + ".csv");
csvFileWriter = new CSVWriter(new FileWriter(outputCSVFile, true),
',', CSVWriter.NO_QUOTE_CHARACTER);
if (checkFileExistsAndEmpty(outputCSVFile)) {
String[] firstRecord = new String[] { gradeReport.getEmpId(),
Integer.toString(gradeReport.getScore()) };
csvFileWriter.writeNext(firstRecord);
}
} catch (IOException ioEx) {
ioEx.printStackTrace();
}
}
Here is the pom entry
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>3.0</version>
</dependency>
您需要通过调用csvFileWriter.close()
关闭csvFileWriter.close()
-理想情况下,此操作应在finally
块中完成。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.