package com.bird.dao;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
import org.junit.Test;
/**
* @use Java普通类实现装载配置文件
* @author Bird
*
*/
public class UserDao {
@Test//无法实现动态修改后呈现,因为直接装载到内存中是不会随着磁盘的文件的更改而更改的
public void update() throws Exception{
InputStream in = UserDao.class.getClassLoader().getResourceAsStream("db.properties");//得到当前类装载器装载配置文件
Properties pro = new Properties();
pro.load(in);
String url = pro.getProperty("url");
String username = pro.getProperty("username");
String password = pro.getProperty("password");
System.out.println(url);
System.out.println(username);
System.out.println(password);
}
@Test//可以时时的获得更改后的数据
public void test() throws Exception{
String path = UserDao.class.getClassLoader().getResource("db.properties").getPath();
FileInputStream in = new FileInputStream(path);
Properties pro = new Properties();
pro.load(in);
String url = pro.getProperty("url");
String username = pro.getProperty("username");
String password = pro.getProperty("password");
System.out.println(url);
System.out.println(username);
System.out.println(password);
}
}