Maven SpringMVC 项目,读取 Resources目录下的资源文件


package com.microfocus.g11n.openl10n.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Properties;

/**
 * Created by bux on 2018/1/28.
 */
public class Localization {
    private static final String L_STRING_FILE = "lStrings.properties";
    private static final Logger logger = LoggerFactory.getLogger(Localization.class);
    private static Properties prop = new Properties();


    public static String getString(String key){
        try {
            if (prop.isEmpty()) {
                prop.load(Localization.class.getClassLoader().getResourceAsStream(L_STRING_FILE));
            }
            return prop.getProperty(key);
        }
        catch (Exception ex)
        {
            logger.error("Load localization file error.", ex);
            return "";
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_38844636/article/details/80494353