Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to test value in a property file?

  1. #1
    Join Date
    Aug 2011
    Thanked 0 Times in 0 Posts

    Default How to test value in a property file?

    Happy Halloween!

    I would like to know how to test a value of a property file.... it seems that making a variable equal to properties.getProperty("key") and then testing that sting value (assume the value is halloween) wont work...

    //imported necessary imports
    public void aMethod(){
         Properties props = new Properties();
              props.load(new FileInputStream(new File("filename.properties"));
              value = props.getProperty("lastHoliday");
              if(value == "halloween"){
         }catch(Exception e){

    in the properties file:


    Do you need to test the value a different way?

  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    My Mood
    Thanked 167 Times in 158 Posts

    Default Re: How to test value in a property file?

    You rarely want to test Strings (or other objects) with ==, use the equals method instead.
    Improving the world one idiot at a time!

Similar Threads

  1. [SOLVED] How do I run test code in different file under a project
    By lostbit in forum Java Theory & Questions
    Replies: 1
    Last Post: September 28th, 2011, 11:31 AM
  2. [SOLVED] Very strange results when reading from a test file
    By DougFane in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: September 11th, 2011, 06:30 PM
  3. Spring - property not autowired
    By timothyd in forum Web Frameworks
    Replies: 0
    Last Post: September 7th, 2011, 07:04 AM
  4. [SOLVED] Issues with a test driver file
    By Gthoma2 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 18th, 2011, 07:54 PM
  5. JavaBean property TextPosition
    By stu1811 in forum Object Oriented Programming
    Replies: 4
    Last Post: August 26th, 2010, 09:33 AM

Tags for this Thread