用来读取properties文件的工具类

public class PropertiesUtil {
    private static Properties properties;

    static {
        properties = new Properties();
        try {
            properties.load(PropertiesUtil.class.getResourceAsStream("/tiku.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String getProperty(String key) {
        return properties.getProperty(key);
    }

    public static String getProperty(String key, String defaultValue) {
        return properties.getProperty(key, defaultValue);
    }

    public static void main(String[] args) {
        System.out.println(getProperty("PAGE_SIZE"));
        System.out.println(getProperty("page_size"));
        System.out.println(getProperty("page_size", "30"));
    }
}

你可能感兴趣的:(工具类,读取Properties)