idea里properties的使用
eclipse里面可以直接创建src目录下的properties文件。
但是idea里稍有不同,需要使用Resource bundle来创建。
1、创建properties文件
2、配置该文件
username = root
password = 123456
url = jdbc:mysql://localhost:3306/test
driver = com.mysql.jdbc.Driver
3、使用
InputStream is = Main.class.getClassLoader().getResourceAsStream("sql.properties");
Properties pro = new Properties();
pro.load(is);
System.out.println(pro.getProperty("url"));
} catch (IOException e) {
e.printStackTrace();
}
会看到输出url . jdbc:mysql://localhost:3306/test