java - Best way to compare big csv files? -


i must application, compares big csv files, each 1 having 40,000 records. have done application, works properly, spends lot of time in doing comparison, because 2 files disordenated or have different records - must iterate (40000^2)*2 times.

here code:

  if (nomfich.equals("car"))     {     while ((linea = br3.readline()) != null)     {                  array =linea.split(",");                 spliteado = array[0]+array[1]+array[2]+array[8];                  filereader fh3 = new filereader(cadena + lista2[0]);                 bufferedreader bh3 = new bufferedreader(fh3);                  find=0;                  while (((linea2 = bh3.readline()) != null))                  {                     array2 =linea2.split(",");                     spliteado2 = array2[0]+array2[1]+array2[2]+array2[8];                       if (spliteado.equals(spliteado2))                     {                          find =1;                     }                  }                 if (find==0)                  {                     bw3.write("+++++++++++++++++++++++++++++++++++++++++++");                     bw3.newline();                     bw3.write("se han incorporado los siguientes cgi en la nueva lista");                     bw3.newline();                     bw3.write(linea);                     bw3.newline();                     aparece=1;                 }                 bh3.close();       } 

i think using set in java option, following post suggests: comparing 2 csv files in java

but before try way, know, if there better options.

thanks all.

hashmap<string, string> file1map = new hashmap<string, string>();  while ((string line = file1.readline()) != null) {   array =line.split(",");   key = array[0]+array[1]+array[2]+array[8];   file1map.put(key, key); }  while ((string line = file2.readline()) != null) {   array =line.split(",");   key = array[0]+array[1]+array[2]+array[8];   if (file1map.containskey(key)) {     //if file1 has same line in file2   }   else {     //if file1 doesn't have line in file2   } } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -