通过属性文件可以提交或者读取属性信息,*.properties
//程序中设置属性信息
Properties properties = new Properties();
properties.setProperty("de", "Germany");
properties.setProperty("cn", "China");
//读取属性值
properties.getProperty("de");
properties.getProperty("cn");
//通过第二个参数设定默认值
properties.getProperty("fr", "France");
//存储到属性文件
properties.store(new FileOutputStream(new File("c:" + File.separator) + "filename.properties"), "commentar");
//读取属性文件
properties.load(new FileInputStream(new File("c:" + File.separator + "filename.properties")));
//存储到XML文件
properties.pro.storeToXML(new FileOutputStream(new File("c:" + File.separator) + "filename.properties"), "commentar");
// 读取XML文件
properties.pro.loadFromXML(new FileInputStream(new File("c:" + File.separator + "filename.properties")));