-1

This code reads from a .properties file

protected String cfgReader(String arg1)
        throws IOException 
        {
    String readVal = null;
    FileInputStream in = new FileInputStream("CFG.properties");
    Properties props = new Properties();
    props.load(in);
    readVal = props.getProperty(arg1);

    in.close();

    FileOutputStream out = new FileOutputStream("CFG.properties");
    props.store(out, null);
    out.close();
        return readVal; 
}

but if I try to do something like:

if(cfgReader("var1") == "n/a"){...}

it doesn't work even if the .properties contains

var1=n/a    
Mureinik
  • 297,002
  • 52
  • 306
  • 350

1 Answers1

2

Strings in Java are objects - they should be compared with the equals method, not the == operator, which checks reference identity:

if (cfgReader("var1").equals("n/a"))
Mureinik
  • 297,002
  • 52
  • 306
  • 350