Answers for "add uuid to csv"

1

add uuid to csv

BufferedReader csvReader = new BufferedReader(new FileReader("Path to existing csv"));
        String delimiter = ","
        List<List<String>> rows = new ArrayList<>();
        String row;
        while ((row = csvReader.readLine()) != null) {
            String[] data = row.split(delimiter);
            rows.add(Arrays.asList(data));
        }
        csvReader.close();

        FileWriter csvWriter = new FileWriter("Path to final csv");
        for (List<String> rowData : rows) {

            csvWriter.append(UUID.randomUUID().toString());
            csvWriter.append(delimiter);
            csvWriter.append(String.join(delimiter, rowData));
            csvWriter.append(System.lineSeparator());
        }
        csvWriter.flush();
        csvWriter.close();
Posted by: Guest on October-07-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language