日期:2014-05-19 浏览次数:20708 次
package com.commons; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.util.HashMap; import java.util.Map; import java.util.Properties; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; public class PropertiesUtils { private static ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(); private static final String DEFAULT_RESOURCE_PATTERN = "classpath:*-tag.properties"; private static final Map<Object, Object> all = new HashMap<Object, Object>(); public static Map<Object, Object> getAll() { return all; } static { try { Resource[] resources = resourcePatternResolver .getResources(DEFAULT_RESOURCE_PATTERN); if (resources != null) { for (Resource r : resources) { Reader in = new InputStreamReader(r.getInputStream(), "UTF-8"); Properties p = new Properties(); p.load(in); all.putAll(p); in.close(); } } } catch (IOException e) { e.printStackTrace(); } } }