It there any possibility to add a new column to existing csv file, means
existing file
userid,name
1,Jim
2,Sally
3,Bob
modified output file
userid,name,time
1,Jim,64913824823208
2,Sally,64913824900056
3,Bob,64913824966956
Thanks in advance
You mean something like this?
CSVReader reader = new CSVReader(new FileReader("input.csv"));
CSVWriter writer = new CSVWriter(new FileWriter("output.csv"), ',');
String[] entries = null;
while ((entries = reader.readNext()) != null) {
ArrayList list = new ArrayList(Arrays.asList(entries));
list.add(xxx); // Add the new element here
writer.writeNext(list);
}
writer.close();
Haven't tried to compile it but something like this should work. There are many options to use OpenCsv (e.g., you can link the data to beans directly), but this is the shorter solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With