【发布时间】:2016-06-13 17:33:50
【问题描述】:
今天我尝试使用java.util.properties 存储Object。我看到很多例子只是使用String 或Integer。这是一个例子:
public static void main(String[] args) {
Properties prop = new Properties();
// add some properties
prop.setProperty("Height", "200");
prop.put("Width", "1500");
// print the list
System.out.println("" + prop);
try {
// store the properties list in an output stream
prop.store(System.out, "config.properties");
} catch (IOException ex) {
ex.printStackTrace();
}
}
那么是否可以将Object 存储在properties 文件或xml 文件中?
【问题讨论】:
-
只需创建自己的文件格式并对其进行解析/写入