Hi, I am trying to read the csv file and fetch the headers and related values in the map and convert it to a list because I want two different lists of emails matching with specific column values as Y and N. If that column is Y, it should return some list of emails present in the CSV file, and if it is N, it should return another list of emails.
My code is below, and it works perfectly in IntelliJ, but I need to use Katalon, and it throws a null pointer exception.
@Keyword
public void readCSVUsingMapAndList() {
String header = "";
String[] headerArray = null;
String csvLine = "";
String[] csvLineArray = null;
File file = new File("C:\\Users\\ju9964\\CREME_MKTG_EMAIL_CONSENT_20220727_01.csv");
Map<String,String> values = new HashMap();
Map<String, List<String>> emailList = new HashMap<>();
List<String> YList = new ArrayList<>();
List<String> NList = new ArrayList<>();
try {
BufferedReader br = new BufferedReader(new FileReader(file))
if((header = br.readLine()) != null) {
if(header != null && header != "")
headerArray = header.split(",");
}
while ((csvLine = br.readLine()) != null) //returns a boolean value
{
csvLineArray = csvLine.split(",");
for (int count = 0; count < headerArray.length; count++) {
values.put(headerArray[count], csvLineArray[count]);
}
if(values.get('PERM_OVERALL').equalsIgnoreCase('Y'))
{
YList.add(values.get('EMAILADDRESS'));
}else {
NList.add(values.get('EMAILADDRESS'));
}
emailList.put('Y',YList);
emailList.put('N',NList);
}
System.out.println(emailList.get("Y"));
System.out.println(emailList.get("N"));
}catch(Exception e) {
e.printStackTrace();;
}
}
Note: If I use equals() method instead of equalsIgnoreCase, it always returns null values.
Can someone please help me to solve this?