Six ways Java reads the properties file

Source: Internet
Author: User

Http://www.open-open.com/lib/view/open1400721838050.html

11. Using the Load () method of the Java.util.Properties class2Example: InputStream in = Lnew Bufferedinputstream (NewFileInputStream (name));3Properties p =NewProperties ();4 p.load (in);5 62. Using the Getbundle () method of the Java.util.ResourceBundle class7Example: ResourceBundle RB =resourcebundle.getbundle (name, Locale.getdefault ());8 9 3. Use the constructor of the Java.util.PropertyResourceBundle classTenExample: InputStream in =NewBufferedinputstream (NewFileInputStream (name)); OneResourceBundle RB =NewpropertyResourceBundle (in); A  -4. The getResourceAsStream () method using the class variable -Example: InputStream in = jproperties.class. getResourceAsStream (name); theProperties p =NewProperties (); - p.load (in); -  -5. The getResourceAsStream () method of Java.lang.ClassLoader obtained using Class.getclassloader () +Example: InputStream in = jproperties.class. getClassLoader (). getResourceAsStream (name); -Properties p =NewProperties (); + p.load (in); A  at6. Using the Getsystemresourceasstream () static method of the Java.lang.ClassLoader class -Example: InputStream in =Classloader.getsystemresourceasstream (name); -Properties p =NewProperties (); - p.load (in); -  - Supplement in  - the getResourceAsStream () method of Javax.servlet.ServletContext can be used in Servlets toExample: InputStream in =context.getresourceasstream (path); +Properties p =NewProperties (); -P.load (in);

Six ways Java reads the properties file

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.