方法一:
PropertyResourceBundle res = (PropertyResourceBundle)
PropertyResourceBundle.getBundle("application-dev"); // properties 文件名
String smtpServer = res.getString("btms.util.email.smtpServer"); //所要获取的值的 key名
String port = res.getString("btms.util.email.port");
String username = res.getString("btms.util.email.username");
String subject = res.getString("btms.util.email.subject");
String password = res.getString("btms.util.email.password");
方法二:根据 org.apache.velocity jar包提供的 PropertiesUtil 类获取
PropertiesUtil propertiesUtil = new PropertiesUtil();
Properties aString = propertiesUtil.load(Path); // properties 文件名 ,本方法文件名必须带后缀名
String aa= aString.getProperty(key); //所要获取的值的 key名
本文介绍了两种在Java中加载属性文件的方法。第一种方法使用PropertyResourceBundle类从资源束中读取属性文件,第二种方法利用org.apache.velocity.jar包中的PropertiesUtil类加载属性文件。这两种方法都是通过提供文件路径和键名来获取相应的属性值。
2731

被折叠的 条评论
为什么被折叠?



