当前位置:首页 > 开发 > Web前端 > 前端 > 正文

ResourceBundle和Properties

发表于: 2013-01-09   作者:CunningFox   来源:转载   浏览:
摘要: 项目需要从绝对路径中取的页面label的value 1.用ResourceBundle取值     public static void main(String[] args) throws MalformedURLException {         String resource
项目需要从绝对路径中取的页面label的value

1.用ResourceBundle取值

    public static void main(String[] args) throws MalformedURLException {
        String resourcePath = "D:/";
        String resourceFileName = "test";
        Locale currentLocale = Locale.getDefault();
        File resourceFile = new File(resourcePath);
        URL resourceUrl = resourceFile .toURI().toURL();
        URL[] urls = {resourceUrl };  
        ClassLoader loader = new URLClassLoader(urls);  
        ResourceBundle bundle = ResourceBundle.getBundle(resourceFileName, currentLocale, loader);
       
        System.out.println(bundle.getString("viewRatings"));
    }

2. 直接IO读取properties文件
    public static void main(String[] args) throws FileNotFoundException,
                                                  IOException {
        InputStream is = new FileInputStream(new File("D:/test.properties"));
        Properties p = new Properties();
        p.load(is);
       
        System.out.println(p.get("viewRatings"));
    }

ResourceBundle和Properties

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号