I tried importing the records from a CSV file using OpenCSV. I observed that OpenCSV was actually missing out some of the entries in the last row of my file. The code is as below. I know that I can do a writeAll operation. But i need individual rows for some other operations. The number of records are around 56000 in my file.
CSVReader reader = new CSVReader(new BufferedReader(new InputStreamReader(new FileInputStream(inputFile))));
CSVWriter writer = new CSVWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(path2+File.separator+fileName)))), ',');
List<String[]> fileContents = new ArrayList<String[]>();
fileContents = reader.readAll();
for(int i=0; i<fileContents.size(); i++){
String[] row = fileContents.get(i);
writer.writeNext(row);
I figured out the error. I wasnt closing the writer. writer.close(); And the file was completely written. Don't know why it doesnt complete writing the file otherwise.