資源綁定器:ResourceBundle
1.隻能讀取字尾為 .properties檔案
2.properties檔案必須在類路徑下
3.在寫路徑的時候,字尾名不能寫
aaa.properties和abc.properties内容是一樣的:
cname=org.example.dao.User
cage=18
public class Client {
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
ResourceBundle resourceBundle=ResourceBundle.getBundle("aaa");
ResourceBundle resourceBundle2=ResourceBundle.getBundle("abc");
System.out.println(resourceBundle.getString("cage"));
System.out.println(resourceBundle2.getString("cname"));
}
}
當檔案報錯:Can't find bundle for base name aaa, locale zh_CN
是因為在普通目錄下
隻需要file--projectStructure将檔案設定如下即可: