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.