配置文件在src目录下
直接上代码了
package com.po.test;
import java.io.IOException;
import java.util.Properties;
import java.util.ResourceBundle;
public class Test {
public static void main(String[] args) {
Properties prop = new Properties();
try {
prop.load(ClassLoader.getSystemResourceAsStream("test.properties"));
String url = (String) prop.get("url");
System.out.println("Properties方法获取:"+url);
} catch (IOException e) {
e.printStackTrace();
}
ResourceBundle bundle = ResourceBundle.getBundle("test");
String url = bundle.getString("url");
System.out.println("ResourceBundle方法获取:"+url);
}
}