/**
* @Author Bob.Z * @Date 2012-7-12 17:32:09 * @E-mail zhaohevip@gmail.com * @Description 资源文件装载的四种方式 * @TODO 【J2EE精英群】 群号:140318536 */Properties properties = new Properties(); // CASE 1 try { ClassLoader loader = PropertiesUtil.class.getClassLoader(); InputStream inStream = loader.getResourceAsStream(propFileName); properties.load(inStream); value = properties.getProperty(propKey); } catch (Exception e) { logger.error("An error occured!"); } // CASE 2 try { properties = PropertiesLoaderUtils.loadAllProperties(propFileName); properties.getProperty(propKey); } catch (Exception e) { logger.error("An error occured!"); } // CASE 3 try { Resource resource = new ClassPathResource(propFileName); properties = PropertiesLoaderUtils.loadProperties(resource); value = properties.getProperty(propKey); } catch (Exception e) { logger.error("An error occured!"); } // CASE 4 try { Resource resource = new ClassPathResource(propFileName); PropertiesLoaderUtils.fillProperties(properties, resource); value = properties.getProperty(propKey); } catch (Exception e) { logger.error("An error occured!"); }
加载配置文件
最新推荐文章于 2024-01-13 23:30:46 发布