zoukankan      html  css  js  c++  java
  • 读取配置文件.property

    在项目中有时需要配置.property文件

    xx.properties配置文件中有数据:

    class.name=com.Fruit

    class.field=pulp

    class.method=eat

    1、项目工程中使用注解@Value方式

    在web项目工程中可以通过@Value("${xx.xx}")来获取.property中配置的

    @Value("${class.name}")

    private String className;

    2、在项目中不适用注解方式

    public class TestProperties

        Properties pro = new Properties();//创建Properties对象

       ClassLoader classLoader = TestProperty.class.getClassLoader();//使用类加载器

       InputStream inputStream = classLoader.getResourceAsStream("xx.properties");//获取class目录下的配置文件

       pro.load(inputStream);//加载

       //获取配置文件中的数据

       String className = pro.getProperty("class.name");

       String field = pro.getProperty("class.field");

       String method = pro.getProperty("class.method");

  • 相关阅读:
    继承
    对象和封装
    类的无参、带参方法
    类和对象
    数组
    循环结构
    选择结构
    变量、数据类型和运算符
    快捷键
    MyEclipse与JDK的配置
  • 原文地址:https://www.cnblogs.com/zj68/p/12830988.html
Copyright © 2011-2022 走看看