Java Learning -021-properties Get a value for a configuration item

Source: Internet
Author: User

During routine scripting, you typically get configuration items in the configuration file to execute the appropriate business logic.

Small two on the yards ... If there is any deficiency, please ask the great God to correct me, I appreciate it!

The source code for getting the configuration item value is as follows:

1     /**2 * Get value from properties by key. Return null When the key is not exist.3      * 4      * @authorAARON.FFP5      * @versionv1.0.0:autouiselenium main.java.aaron.java.tools Fileutils.java propertiesgetvalue, 2014-11-20 16:31:22 EXP $ 6      * 7      * @paramprop:properties8      * @paramKey:key9      * @returnStringTen      */ One      Publicstring Propertiesgetvalue (Properties prop, String key) { AString value = ""; -          -         if( This. Propertieskeyisexist (prop, key)) { theValue =Prop.getproperty (key); -}Else { -Value =NULL; -         } +          -         returnvalue; +}
Java Get Properties config file source code

The test source is as follows:

1     /**2 * Test:get value from properties file by key3      * 4      * @authorAARON.FFP5      * @versionv1.0.0:autouiselenium test.java.aaron.java.tools Fileutilstest.java test_propertiesgetvalue, 2014-11-20 16:40:15 EXP $6      *7      */8 @Test9      Public voidTest_propertiesgetvalue () {Ten          This. Message = "\n\n\ntest:fileutils.propertiesgetvalue (Properties prop, String key)"; One          This. Logger.debug ( This. message); A          -          This. Fu =NewFileUtils (); -String filename = This. constantslist. Projecthome + This. constantslist. Fileseparator + the"Testng-temp" + This. constantslist. Fileseparator + "Propertiesread.properties"; -          -Properties prop = This. Fu.propertiesread (filename); -          +         //print-1 - prop.list (System.out); +          ASystem.out.println ("\ n")); at          -Assert.assertequals ( This. Fu.propertiesgetvalue (prop, "host"), "127.0.0.1", "Test case failed."); -}
Test Source

The execution results are as follows:

At this point, Java learning -021-properties get configuration items corresponding to the value of a smooth end, I hope this article can give beginners Java you a reference.

Finally, very grateful to the pro-stop, I hope this article can be pro helpful. Warmly welcome the kiss to discuss together and progress together. Thank you so much! ^_^

Java Learning -021-properties Get a value for a configuration item

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.