One: Java read (only read the properties file under the class file)
private static String Smsurl;//url
Static {
Properties prop = new properties ();
URL url= SendSMS.class.getResource ("/sms.properties");
try {
prop.load (Url.openstream ());
Smsurl = Prop.getproperty ("Smsurl"). Trim ();
catch (Exception e) {
e.printstacktrace ();
}
}
Two: Spring read
1. Read the files under the class file
static {
Resource Resource = new Classpathresource ("/<span style=" font-family:arial, Helvetica, Sans-serif; " >sms.properties</span><span style= "font-family:arial, Helvetica, Sans-serif;" > ");</span>
try {
Properties prop = propertiesloaderutils.loadproperties (Resource);
Evaluateurl=prop.getproperty ("<span style=" font-family:arial, Helvetica, Sans-serif; " >smsurl</span><span style= "font-family:arial, Helvetica, Sans-serif;" > "). Trim ();</span>
} catch (IOException e) {
//TODO auto-generated catch block
e.printstacktrace ();
}
}
2. Read the files under the Web path
<pre name= "code" class= "Java" >static {
Resource Resource = new Classpathresource (".. /config/config.properties ");
try {
Properties prop = propertiesloaderutils.loadproperties (Resource);
Evaluateurl=prop.getproperty ("Jysystem.evaluateurl"). Trim ();
catch (IOException e) {
//TODO auto-generated catch block
e.printstacktrace ();
}
}
Tomcat Down Path: