2

I have a csv file with 2 rows - column headers and values.I need to access the value of each column and update the value.

this script is proving value in a new row.

CSVWriter writer=new CSVWriter(new FileWriter("C:\\Try.csv",true));     
writer.writeNext(pNumber);  
writer.close();
Pino
  • 7,468
  • 6
  • 50
  • 69
aathira shaji
  • 41
  • 1
  • 9

2 Answers2

1
BufferedReader reader = new BufferedReader(new FileReader("C:\\Try.csv"));
List<String> lines = new ArrayList<>();
String line = null;
while ((line = reader.readLine()) != null) {
    lines.add(line);
}

System.out.println(lines.get(0));

You can access the lines after that by using lines.get(lineNumber) and do your operation. Hope this gives an idea to start with.

Mebin Joe
  • 2,172
  • 4
  • 16
  • 22
1

Simple Steps to do this:

  1. Create a new .csv file

  2. Read your file

  3. While reading your file, write to your new file and do the changes if necessary.

You can also check the similar question here: what is the best way to edit csv file