add uuid to csv

Solutions on MaxInterview for add uuid to csv by the best coders in the world

showing results for - "add uuid to csv"
Greta
06 Jan 2020
1BufferedReader csvReader = new BufferedReader(new FileReader("Path to existing csv"));
2        String delimiter = ","
3        List<List<String>> rows = new ArrayList<>();
4        String row;
5        while ((row = csvReader.readLine()) != null) {
6            String[] data = row.split(delimiter);
7            rows.add(Arrays.asList(data));
8        }
9        csvReader.close();
10
11        FileWriter csvWriter = new FileWriter("Path to final csv");
12        for (List<String> rowData : rows) {
13
14            csvWriter.append(UUID.randomUUID().toString());
15            csvWriter.append(delimiter);
16            csvWriter.append(String.join(delimiter, rowData));
17            csvWriter.append(System.lineSeparator());
18        }
19        csvWriter.flush();
20        csvWriter.close();