读取属性(file.properties)文件值

读取属性文件的值file.properties:
新建file.properties文件,内容如下:

name=shp
age=18
sex=

在测试类中编写

package com.vimochina.vimo.dji;

import com.vimochina.vimo.config.UrlProperties;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @Auther shp
 * @data2020/6/1114:34
 * @description
 */
public class InputPropertis {


    public static void main(String[] args) throws IOException {

        ClassLoader classLoader = UrlProperties.class.getClassLoader();
        InputStream is = classLoader.getResourceAsStream("file.properties");
        Properties properties = new Properties();
        properties.load(is);
        System.out.println(properties.getProperty("name"));
        System.out.println(properties.getProperty("age"));
        System.out.println(properties.getProperty("sex"));

    }


}

你可能感兴趣的:(读取属性(file.properties)文件值)