Can I work with the values ​​in the text file properties?

For example, read the value and add it to logical operations?

If not, then with what can you read and work with the values ​​in a text file?

Properties props = new Properties(); try { props.load(in); } catch (IOException e1) { e1.printStackTrace(); } String answer = props.getProperty("OTBET"); if(answer == "4") System.out.print("answer = 4"); 

The problem is that I can not compare, nothing happens!

  • four
    yes you can. What is the problem with you? - Senior Pomidor
  • Properties props = new Properties (); try {props.load (in); } catch (IOException e1) {e1.printStackTrace (); } String answer = props.getProperty ("OTBET"); if (answer == "4") The problem is that I cannot compare, nothing happens - Mityay
  • @ answer.equals("4") necessary. lines through == do not compare - Senior Pomidor
  • Thank you very much, I will know! - Mityay

1 answer 1

java:

 Properties properties = new Properties(); properties.load(this.getClass().getResourceAsStream("/propertiesfile.properties")); String str = properties.getProperty("a.string"); //str ="test string from property file" 

Property file:

 a.string=test string from property file