创建以.properties结尾的文件。如:config.properties以key=value形式保存数据。 //例子 driverClass=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/test user=user password=password 读取配置 Properties prop = new Properties(); //InputStream in = this.getClass().getClassLoader().getResourceAsStream("config.properties") InputStream in = this.getClass().getResourceAsStream("/config.properties") //加载文件 prop.load(in); //根据key获取value值 prop.getProperty("key"); //文件保存属性 OutputStream out = new FileOutputStream("config.properties", true);//true表示追加打开 prop.setProperty("name", "wind"); prop.store(out, "comment"); out.close();