Using the Properties class to modify the key value pairs in the Replace properties type file in Java __java

Source: Internet
Author: User
--------------------------------------Signature
Recently, the company needs to do a function: In the Web project, using Web pages to dynamically modify the connection parameters in JDBC. In addition to directly changing the value of the bean in the spring container, there is a modification of the connection parameter key value pairs in the jdbc.properties. So how do you get to the value of replacing a pair of key-value pairs with a key?

--------------------------------------Code

String Password = request.getparameter ("password");
String path = Request.getsession (). Getservletcontext (). Getrealpath ("/") + "web-inf\\classes\\cfg\\properties\\ Jdbc.properties ";
InputStream in = null;
OutputStream out = null;
Try {
	Properties prop = new properties ();

	in = new FileInputStream (path);
	Prop.load (in);//Deposit input stream to prop key value pair

	Prop.setproperty ("Jdbc.password", password);//change or save key value pair out
	= new FileOutputStream (path); 
	Prop.store (out, null); Put the prop key value pair into out output stream
} catch (Exception e) {
	e.printstacktrace ();
} finally {
	in.close ();
	Out.close ();
}


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.