💠

💠 2025-04-25 13:53:45


配置文件格式

conf或者ini

1
2
3
4
    [main]
    debug=true
    [client]
    timeOut=10

Toml

Github: toml

HOCON

Human-Optimized Config Object Notation

lightbend/config: configuration library for JVM languages using HOCON files
Official Doc

Nginx 的配置文件就是使用该格式


Properties

Java中的使用

通过ResourceBundle获取classPath下的属性文件

1
2
    ResourceBundle bundle = ResourceBundle.getBundle("test");
    String city = bundle.getString("name");

通过Properties对象获取配置文件

1
2
3
    Properties pro = new Properties();
    pro.load(new FileInputStream(new File("./test.properties")));
    String name = (String) pro.get("name");

使用Properties保存配置文件

1
2
3
4
    Properties pro = new Properties();
    pro.setProperty("name", "java");
    pro.setProperty("study", "sdf");
    pro.store(new FileOutputStream(new File("test.properties")), "one file");

XML

可阅读性强, 结构清晰, 但是太繁杂, 信息承载比重小


YAML

yaml is ain’t markup language

Java中的使用

  • 使用这个用来自定义配置文件要特别注意采用小写(不然影响反射中set方法)

  • Jackson操作yaml


JSON

Google 规范

JSON in Java

RealAlexandreAI/json-repair: 🔧 Repair JSON!Solution for JSON Anomalies from LLMs.
HAibiiin/json-repair: Repair JSON! A Java library for fixing JSON anomalies generated by LLMs.

BSON

Smile

二进制的JSON Wikipedia: Smile