JAVA 读取配置文件

static Logger logger = LoggerFactory.getLogger(LoginShiro.class);
private static String jdbcUrl;
private static String jdbcUserName;
private static String jdbcPassword;

static{
InputStream inStream= null;
try {
String filePath=LoginShiro.class.getClassLoader().getResource("config/jdbc.properties").getFile();
//String configPath=LoginShiro.class.getResource("/").getPath()+"config/jdbc.properties";
FileInputStream in = new FileInputStream(filePath);
Properties properties = new Properties();
properties.load(in);
jdbcUrl = properties.getProperty("jdbc_url");
jdbcUserName = properties.getProperty("jdbc_username");
jdbcPassword = properties.getProperty("jdbc_password");
} catch (Exception e) {
e.printStackTrace();
}finally{
if(inStream!=null){
try {
inStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

posted @ 2018-05-14 17:19  伍春晖  阅读(251)  评论(0编辑  收藏  举报