In Java application development, it is often necessary to read a configuration file to obtain system parameters or configuration information. Profiles can be used in XML format files, and in Java. properties files are used specifically as configuration files. In Java, class properties are used to process configuration file-related reads. The following is an example of obtaining a value based on the provided key.
public static string GetValue (String key)
{
Properties P=new properties ();
FileInputStream fis;
String url = new File (""). GetAbsolutePath () + file.separator+ "config.properties"; Gets the config.properties configuration file absolute path
try {
fis = new FileInputStream (URL) located in the engineering root directory;
P.load (FIS);
Fis.close ();
} catch (Exception e) {
//TODO auto-generated catch block
System.out.print (' Problems with properties ');
E.printstacktrace ();
}
return P.getproperty (key);
}