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();
}
}
}
}

猜你喜欢

转载自www.cnblogs.com/whwu123/p/9037111.html