Class PropertiesConfiguration
java.lang.Object
com.dianxin.tori.base.configuration.properties.PropertiesConfiguration
Example code:
server.port=8080
bot.name=AjaxBot
# Dùng dấu | làm splitter
bot.owners=123456|987654|112233
debug.mode=true
public void testProperties() {
File file = new File("app.properties");
// Khởi tạo với splitter là "|"
EmbeddedPropertiesConfiguration config = PropertiesConfiguration.of(file, "|");
// 1. Lấy String/Int/Boolean
String name = config.getString("bot.name"); // "AjaxBot"
int port = config.getInt("server.port"); // 8080
boolean debug = config.getBoolean("debug.mode"); // true
// 2. Lấy List (Splitter hoạt động ở đây)
List owners = config.getStringList("bot.owners");
// Kết quả: List chứa ["123456", "987654", "112233"]
// 3. Set List mới và lưu lại
List newAdmins = List.of("Mino", "Dianxin");
config.set("bot.admins", newAdmins); // Sẽ lưu thành: bot.admins=Mino|Dianxin
try {
config.save(file);
} catch (Exception e) {
e.printStackTrace();
}
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionTạo một cấu hình Properties từ file.
-
Constructor Details
-
PropertiesConfiguration
public PropertiesConfiguration()
-
-
Method Details
-
of
Tạo một cấu hình Properties từ file.- Parameters:
file- File .properties cần loadsplitter- Ký tự phân cách dùng cho List (ví dụ "," hoặc "|"). Mặc định là ",".
-
of
-