Skip to content

Profile

kcp edited this page Jul 13, 2020 · 2 revisions

title: 多种配置文件格式 date: 2018-11-21 10:56:52 tags: - 基础 categories: - 计算机基础

目录 start

  1. 配置文件格式
    1. conf或者ini
    2. Toml
    3. HOCON
    4. Properties
      1. Java中的使用
    5. XML
    6. YAML
      1. Java中的使用
    7. JSON
      1. BSON
      2. Smile

目录 end|2020-07-05 14:58|


配置文件格式

conf或者ini

    [main]
    debug=true
    [client]
    timeOut=10

Toml

Github: toml

HOCON

Human-Optimized Config Object Notation

Official Doc

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


Properties

Java中的使用

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

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

通过Properties对象获取配置文件

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

使用Properties保存配置文件

    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中的使用

  • Springboot将这种配置文件引入了我的视野,使用这个用来自定义配置文件要特别注意采用小写(不然影响反射中set方法)

  • Jackson操作yaml


JSON

Google 规范

JSON in Java

BSON

Smile

二进制的JSON Wikipedia: Smile

Summary

Clone this wiki locally