无论你的tomcat在哪,利用资源绑定的话很容易就可以操作你的配置文件了
import java.util.*;
public class PropertyFile {
public PropertyFile() {
}
public static String getValue(String key) {
ResourceBundle rb = ResourceBundle.getBundle("application");
//这句话就是绑定了名为application的资源文件,后缀都不用写的
String temp = rb.getString(key);
return temp;
}
}
这样的话,由于getvalue()是个静态的方法,所以可以直接来用
比如你在别的文件中可以用
String username = PropertyFile.getValue("username");
String password = PropertyFile.getValue("password");
String url = PropertyFile.getValue("url");
String driver = PropertyFile.getValue("driver");
在项目当中,你的properties文件要放在和你的源文件在一个目录就可以了
import java.util.*;
public class PropertyFile {
public PropertyFile() {
}
public static String getValue(String key) {
ResourceBundle rb = ResourceBundle.getBundle("application");
//这句话就是绑定了名为application的资源文件,后缀都不用写的
String temp = rb.getString(key);
return temp;
}
}
这样的话,由于getvalue()是个静态的方法,所以可以直接来用
比如你在别的文件中可以用
String username = PropertyFile.getValue("username");
String password = PropertyFile.getValue("password");
String url = PropertyFile.getValue("url");
String driver = PropertyFile.getValue("driver");
在项目当中,你的properties文件要放在和你的源文件在一个目录就可以了