Java properties File properties Common Operations Tool class

Source: Internet
Author: User
For java.util.Properties classes, we usually only need to do the following 3 learning goals:
1, understanding the properties of the file, understand its meaning, will correctly create properties file.
2, will use the Java.util.Properties class to operate the properties file.
3, master the relative path, can correctly write a properties file relative path.
And in peacetime work, will encounter a variety of needs, the following is a package.
Package com.herman.util;
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.IOException;
Import Java.io.InputStream;

Import java.util.Properties; /** * Properties File Operation Tool Class * @author Herman.xiong * @date 2015-1-29 pm 04:27:19 * @version V3.0 * @since JDK 1.6,tomcat 
	6.0 * * Public class Propertiesutil {private static properties prop = new properties ();
	private static InputStream in;
	
	private static final String path= "Src/com/herman/config/conf.properties";
	/** * Loading * * static{init ();
			}/** * Initialize/private static void Init () {try {in=new FileInputStream (new File path);
		Prop.load (in);
		catch (Exception e) {e.printstacktrace ();
		}/** * Closes InputStream * @author Herman.xiong * @date 2015-1-30 a.m. 09:41:04/private static void close () { 
		try {if (null!= in) in.close ();
		catch (Exception e) {e.printstacktrace ();
	}/** * Reload properties * @author Herman.xiong * @date 2015-1-30 09:41:04 */public static void reload () {close ();
	Prop.clear ()//Clears all loaded key-value pairs init (); /** * Delete all key values * @author Herman.xiong * @date 2015-1-30 a.m. 09:42:04/public static void RemoveAll () {Close (
		);
		File File=new file (path);
		if (file.exists ()) File.delete ();
		try {if (!file.exists ()) New file (path). CreateNewFile ();
		catch (IOException e) {e.printstacktrace (); /** * Output All content to console * @author Herman.xiong * @date 2015-1-30 a.m. 09:42:33/public static void Outlist () {p
	Rop.list (System.out);
		public static void Main (string[] args) {System.out.println (Prop.getproperty ("abc"));
		Outlist ();
		Reload ();
		Outlist ();
		RemoveAll ();
		System.out.println ("Reload ...");
	Outlist ();
 }
}

You are welcome to pay attention to my blog. If you have questions, please add QQ Group: 135430763 study together.

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.