Skip to content

Profile

kcp edited this page May 16, 2019 · 2 revisions

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

目录 start

  1. 数据序列化格式
    1. conf或者ini
    2. properties
      1. Java中的使用
    3. XML
    4. YAML
      1. Java中的使用
    5. JSON
    6. BSON
    7. Smile
      1. Jackson

目录 end|2019-05-10 18:10|


数据序列化格式

conf或者ini

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

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

Jackson

Summary

Clone this wiki locally