parsing - Parse CSV pull data and compare but not working. Java -


i have csv file created. trying pull data , run check data.

csv file contents.

"12/05/14","hay square","10.00","10","","","" "12/05/14","hay round","75","1","","","" "12/05/14","feed","12.50","10","","","" "12/05/14","feet","10","","trusty","","" "12/05/14","feed","4","5","","","" "12/05/14","wormer","12.75","","trusty","","" "12/05/14","feed","12","10","","","" "","feed","","","","","" "12/05/14","medicine","124.85","","sunny","","" "12/05/14","feet","90","","speedy","","" 

i using basic code , print works fine print finds not compare via if statement. have searched everywhere , found nothing. strange since think commonly done.

as can see in code looking "feed" , want print found. test code greater project unfinished.

import java.io.bufferedreader; import java.io.filenotfoundexception; import java.io.filereader; import java.io.ioexception; import java.util.arrays;  public class readcsv {    public static void main(string[] args) {      readcsv obj = new readcsv();     obj.run();    }    public void run() {      string csvfile = "c:/horse/horsespending.csv";     bufferedreader br = null;     string line = "";     string cvssplitby = ",";      try {          br = new bufferedreader(new filereader(csvfile));         while ((line = br.readline()) != null) {                  // use comma separator             string[] country = line.split(cvssplitby);             string test = country[1].tostring();             string tester = "\"feed\"";             system.out.println("check " + country[1]);             if(test == tester){             system.out.println("found");                         }          }      } catch (filenotfoundexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     } {         if (br != null) {             try {                 br.close();             } catch (ioexception e) {                 e.printstacktrace();             }         }     }      system.out.println("done");   }          } 

output:

check "purchase" check "hay square" check "hay round" check "feed" check "feet" check "feed" check "wormer" check "feed" check "feed" check "medicine" check "feet" done 

you don't compare strings in java ==, instead use:

test.equals(tester) 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -