从properties配置中获取值
1. 创建一个properties文件

2. 测试代码
public class ResourceTest {
//测试ResourceBundle.getBundle
public static void main(String[] args) throws UnsupportedEncodingException {
System.out.println("测试resoucebundle");
ResourceBundle bundle = ResourceBundle.getBundle("config/test");
String str = bundle.getString("bb");
//解决中文乱码问题
String str1 = new String(bundle.getString("bb").getBytes("ISO-8859-1"),"utf-8");
System.out.println(str);
System.out.println(str1);
}
从Properties配置文件读取值
本文介绍了一种从Java的Properties配置文件中读取值的方法。通过使用ResourceBundle.getBundle方法,可以加载指定的配置文件,并通过getString方法获取特定的配置项。此外,还提供了解决中文乱码问题的解决方案。
368





