Java OpenCSV How to edit specific cells from csv file -


i have csv file looks this: http://gyazo.com/5dcfb8eca4e133cbeac87f514099e320.png

i need figure out how can read specific cells , update them in file.

this code using:

import java.util.list; import java.io.filereader; import java.io.filewriter; import java.io.ioexception;  import com.opencsv.*;  public class readcsv {      private static final char separator = ';';      public static void updatecsv(string input, string output, string  replace, int row, int col) throws ioexception {               csvreader reader = new csvreader(new filereader(input),separator);             list<string[]> csvbody = reader.readall();             csvbody.get(row)[col]=replace;             reader.close();              csvwriter writer = new csvwriter(new filewriter(output),separator,' ');             writer.writeall(csvbody);             writer.flush();             writer.close();     }       public static void main(string[] args) throws ioexception {          string source = "townhall_levels.csv";         string destiantion="output.csv";         readcsv.updatecsv(source, destiantion, "lol", 1, 1);      }  } 

in code trying change a1 "lol" example test see if works following error:

exception in thread "main" java.lang.arrayindexoutofboundsexception: 1     @ readcsv.updatecsv(readcsv.java:16)     @ readcsv.main(readcsv.java:30) 

how should go achieving goal , fixing error?

csv file: www.forumalliance.net/townhall_levels.csv

you're using ;as separator parse file. file uses ,. also, using space quote char doesn't make sense. should use " instead, since that's file uses.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -