Q: Merging csv file Please help me in java code. I have 2 CSV FILE
a.csv contains "zip","name","place"
b.csv contains "zip","latitude","longitude"
I need to merge the following columns with the same zip and save in another csv file
output.csv file will be:
"zip","name","place","latitude","longitude"
how am i going to code this? thank you.
I have read this a.csv but i dont know how to merge.
Here's my code in reading my first csv file
public class Merge{public static void main(String[]args ) throws Exception {
        String csvFile ="a.csv";
        BufferedReader br = null;
        String line = "";
        String cvsSplitBy = ",";

try{

    br = new BufferedReader(new FileReader(csvFile));
    while ((line = br.readLine()) != null) {

        // use comma as separator
        String[] cFile = line.split(cvsSplitBy);
    System.out.println("" + cFile[1] + " " + cFile[2] + " ");

    }

} catch (FileNotFoundException e) {
e.printStackTrace();
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
} finally {
    if (br != null) {
        try {
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

System. out. println("Done");

}
   }

A: I think you should write the below logic to achieve this. This is just an idea.. go ahead and implement if you get any error in any specific area. You ware welcome to get back with your questions.


*

*Read csv 1, populate an array (array 1)

*Read csv 2, populate another array (array 2)

*Loop both the array check the zip and merge in 3rd array.. something like below
for(loop over array 1)
// get the zip from array1
for(loop over array 2)
// get the zip from array2
   if(zip1 == zip2)
      then merge and put the data in another array(array3) and break this loop

*Write this array3 in a new csv file

