1 package test; 2 3 import java.io.IOException; 4 import java.io.InputStream; 5 import java.util.Properties; 6 7 public class TestProperties { 8 public static void main(String [] args) { 9 //读取数据库参数配置 10 InputStream inputStream = TestProperties.class.getClassLoader().getResourceAsStream("jdbc.properties"); 11 12 Properties p = new Properties(); 13 try{ 14 p.load(inputStream); 15 System.out.println(p.getProperty("db.username")); 16 System.out.println(p.getProperty("db.password")); 17 System.out.println(p.getProperty("db.dataBaseName")); 18 System.out.println(p); 19 }catch (IOException e) { 20 e.printStackTrace(); 21 } 22 23 } 24 }
db.username=root db.password= db.dataBaseName = jeesite
运行结果: