java 在xml文件中怎么获取配置文件中的参数

2026年08月30日 02:04
有1个网友回答
网友(1):

public class ReadConf extends Properties{
public ReadConf() {
InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream("conf.xml");
try {
this.loadFromXML(in);
System.out.println( this.getProperty("db.uri.244"));
in.close();
} catch (Exception e) {
e.printStackTrace();
}

}

public static void main(String[] args) {
ReadConf a = new ReadConf();
}
}

注意 xml文件要在src 目录下