Java: how to read the properties file outside the jar package)

Source: Internet
Author: User

You cannot directly do this. If you want to dynamically modify the configuration information, you can only store it as a file, rather than package it.

Two other methods:
◎ Package properties separately, and thenProgramTo modify the attributes, use Java zip to re-package the properties. Jar. This is not recommended;
◎ Save the modified properties and generate a dedicated file. During loading, use the JAR file first, and then read the dedicated file to overwrite the modified properties.

========================================================== ========================================================

Generally, the properties file is used in the project. If the application is packaged into a jar package, you need to re-create the jar after modifying the properties file, which is very troublesome.

So I mentioned the properties file to the jar package statistics directory, so you don't need to re-package it after modification, which makes it easier to use.

CodeAs follows:
String profilepath = system. getproperty ("user. dir") + "\ filename. properties ";
Inputstream in = new bufferedinputstream (New fileinputstream (profilepath ));
Resourcebundle = new propertyresourcebundle (in );

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.