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!"); }
Properties 文件读取方式
最新推荐文章于 2022-05-12 15:55:57 发布