Read and write Java configuration files

Source: Internet
Author: User

Recently in a crawler project, the use of a read-write configuration file method, recorded in the future may be used.

Properties Pro =NewProperties ();BooleanIsFirst =true;//Read the file from the class load path, so the file location requires lil bit inputstream in= Propertiesutil.class. getClassLoader (). getResourceAsStream ("Config.properties");p ro.load (in);//Get the Properties property IsFirst= Boolean.parseboolean (String) pro.get ("Isfirststart") ; In.close ();//Gets the path where the properties are located string sourceURL= This. GetClass (). getClassLoader (). GetResource ("Config.properties"). toString ();
Intercept one part of it, (I know it under an experiment) sourceURL
= Sourceurl.substring (6, Sourceurl.length ());p Ro.setproperty ("Isfirststart", "false");
FileOutputStream
out
=NewFileOutputStream (sourceURL);
The modified storage pro.store (out,
"Is first start"); Out.close ();
isfirststart=true//config.properties file contents

Read and write Java configuration files

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.