public static String confPath = "D:/demo.properties";
private static Properties getProp() throws IOException{
Properties prop = new Properties();
FileInputStream inputfile = new FileInputStream(confPath);
prop.load(inputfile);
inputfile.close();
return prop;
}
public static void main(String[] args) throws IOException {
Properties prop = getProp();
//读取
String port = prop.get("port").toString();
String user = prop.get("username").toString();
String ip = prop.get("ip").toString();
String password = prop.get("password").toString();
System.out.println(ip+":"+port+":"+user+":"+password);
//修改
prop.setProperty("ip", "127.0.0.1");
OutputStream os = new FileOutputStream(confPath);
prop.store(os, null);
}