您的位置:首页 > 数据库

用静态代码块读取数据库配置文件:tResourceAsStream的配置文件路径问题

2015-06-19 00:00 465 查看
摘要: getResourceAsStream

package properTest;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Test {
public static String driver = null;
public static String url = null;
public static String username = null;
public static String password =null;

static{
InputStream inputStream = String.class.getResourceAsStream("/db.properties");
Properties properties = new Properties();
try {
properties.load(inputStream);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver = properties.getProperty("driver");
url = properties.getProperty("url");
username = properties.getProperty("username");
password = properties.getProperty("password");
}
}


要注意:db.properties文件要放在src目录下!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: