Java读写properties配置文件

File in = new File("src" + File.separator + "conf.properties");
Properties properties = new Properties();
properties.load(new FileInputStream(in));

System.out.println(properties.getProperty("user"));

以下是properties内容:

user=admin
passwd=123

File out = new File("conf2.properties");
properties.setProperty("k", "v");
properties.store(new FileOutputStream(out), "写备注");

xml

File in = new File("conf.xml");
Properties properties = new Properties();
properties.loadFromXML(new FileInputStream(in));

原文地址:https://www.cnblogs.com/sysout/p/5184341.html