Java Change properties file does not need to restart Web service read the most recently modified value __web

Source: Internet
Author: User


Write configuration in project development is written in the properties file, but sometimes you need to change the value, but find that you need to restart the service to take effect


/**
	 * Initialization profile *
	 /public
	void init () {
		
		try{inputstream is
			= Config.class.getResourceAsStream ("/ Res/config.properties ");
			Properties = new properties ();
			Properties.load (IS);
			
		} catch (Exception e) {
			throw new RuntimeException ("Failed to get Properties!");
		}
	


It was later found that this load method would load the config.properties file into memory and fetch the file information directly from memory the next time it needed to read, rather than read it again.
So you need to change the way the input stream gets to the file.


	String path = Config.class.getClassLoader (). GetResource ("/res/config.properties"). GetPath ();  
	InputStream is = new FileInputStream (path);  
	Properties.load (IS);  



Related Article

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.