I need to make sure that the csv I create from sql resultset dump using opencsv api is successful operation or not.
Right now I am using CSVWriter to write into the csv , now how would I use the CSVReader to read the line count in csv (assuming each resultset row is saved in 1 line in CSV) and compare that count with the resultset row count.
If the two are same its a success or else a failure.
I am dumping the full resultset into the csv file as follows
File csvfile = new File ("erpimport_"+ getDateTimeString()+ ".csv");
CSVWriter writer = new CSVWriter(new FileWriter(csvfile), ',','"',';');
boolean includeHeaders = true;
ResultSet rs = dbtype.executeQuery(sQuery);
writer.writeAll(rs, includeHeaders);
writer.close();
Is this check a valid method to test the success or failure of writing to csv?
also how would I get the line count in CSV using the CSVReader.
Thanks
Priyank
If I was verifying the functionality of an external library, I probably wouldn’t use that same library to do it. A possible solution would be to scan through the file again with a
BufferedReader, and make a count of the lines as you go, as follows:Then you could compare
lineCountwith your expected value. Of course this may not be the most efficient solution, depending on how frequently you want to perform this check, and the size of the files output.