Posted on 2009-06-17 22:38
eric_xu 阅读(248)
评论(0) 编辑 收藏 所属分类:
Java
package sjtu.rfid;
import java.util.ResourceBundle;
public class ConfigBundle {
private static ResourceBundle configBundle = null;
static{
configBundle = ResourceBundle.getBundle("config");
}
public static String getUsername() {
String username = null;
try {
username = configBundle.getString("username");
} catch (Exception e) {
return null;
}
return username;
}
public static String getPassword() {
String password = null;
try {
password = configBundle.getString("password");
} catch (Exception e) {
return null;
}
return password;
}
public static void main(String[] args){
System.out.println(ConfigBundle.getUsername());
System.out.println(ConfigBundle.getPassword());
}
}
将XML转为Properties处理
Properties prop = new Properties();
prop.loadFromXML(ClassLoader.getSystemResourceAsStream(CONFIG));
String url = prop.getProperty(URL);
String user = prop.getProperty(USER);
String password = prop.getProperty(PASSWORD);