zoukankan      html  css  js  c++  java
  • 用过的这些方法—读取properties配置文件

    代码写得多了,对于同一功能的代码也会遇到多种实现,权且记录一下。

      读取properties文件

      1.使用ResourceBundle加载

        ResourceBundle bundle = ResourceBundle.getBundle("MyResource",Locale.getDefault()); //读取工程类路径下的 MyResource.properties文件,当然也可以为其他名字,例如:conf.properties
        String name = bundle.getString("name"); 
        System.out.println(name);

      2.使用Properties加载

         Properties prop = new Properties();
       prop.load(new FileInputStream(new File("conf/config.properties")));  //注意:此方法加载文件路径
       //
    prop.load(XX.class.getClassLoader().getResourceAsStream("conf.properties"))); //注意:此方法读取工程类路径下 的conf.properties文件
       String name = prop.getProperty("name");
       System.out.println(name);

      注意:简单测试了一下,上面两种方式效率类似

      3.自己来解析文件,读取配置,代码暂略吧..闲了再写

  • 相关阅读:
    JS判断页面是否加载完成
    简单的前端验证码
    如何让旧浏览器支持HTML5新标签
    JSON使用(4)
    JSON语法(3)
    JSON简介(2)
    JSON教程(1)
    jQuery-noConflict()
    jQuery
    jQuery
  • 原文地址:https://www.cnblogs.com/baby-bear/p/4005124.html
Copyright © 2011-2022 走看看