view plainprint?
package combirddao;
import javaioFileInputStream;
import javaioInputStream;
import javautilProperties;
import orgjunitTest;
/**
* @use Java普通类实现装载配置文件
* @author Bird
*
*/
public class UserDao {
@Test//无法实现动态修改后呈现因为直接装载到内存中是不会随着磁盘的文件的更改而更改的
public void update() throws Exception{
InputStream in = UserDaoclassgetClassLoader()getResourceAsStream(dbproperties);//得到当前类装载器装载配置文件
Properties pro = new Properties();
proload(in);
String url = progetProperty(url);
String username = progetProperty(username);
String password = progetProperty(password);
Systemoutprintln(url);
Systemoutprintln(username);
Systemoutprintln(password);
}
@Test//可以时时的获得更改后的数据
public void test() throws Exception{
String path = UserDaoclassgetClassLoader()getResource(dbproperties)getPath();
FileInputStream in = new FileInputStream(path);
Properties pro = new Properties();
proload(in);
String url = progetProperty(url);
String username = progetProperty(username);
String password = progetProperty(password);
Systemoutprintln(url);
Systemoutprintln(username);
Systemoutprintln(password);
}
}