0

Below is the data format in my CSV file

userid,group,username,status

In my Java code I delimited the data by using , as delimiter

Eg:

normal scennario in which my code works fine:

1001,admin,ram,active

in this scenario(user with firstname,lastname) when i take the status of the 1002 user it is coming as KUMAR since it is taking 4th column as status

1002,User,ravi,kumar,active

Kindly help me on how to change the code logic so that it works fine for both the scenenarios

1ac0
  • 2,875
  • 3
  • 33
  • 47
  • 2
    Check out the "Related" questions over to the right. There is one with over 100 upvotes which is on this same subject. – DOK Mar 05 '14 at 18:14
  • possible duplicate of [Dealing with commas in a CSV file](http://stackoverflow.com/questions/769621/dealing-with-commas-in-a-csv-file) – aliteralmind Mar 05 '14 at 18:15

1 Answers1

0

You can use OpenCSV library.

CSVReader csvReader = new CSVReader(new FileReader(fileName),';');
List<String[]> rows = csvReader.readAll();

then you can test the first column : if rows.get(0)[0] == 1002 ....

javacurve
  • 157
  • 1
  • 1
  • 13