java读properties配置文件中的值

思维导图:

在这里插入图片描述

我这边使用的是类加载器的方法,获取properties文件

案例代码如下:

PropertiesTest

package com.lbl.properties;

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

public class PropertiesTest {
    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        InputStream property = PropertiesTest.class.getClassLoader().getResourceAsStream("resource.properties");
        properties.load(property);
        System.out.println(properties.getProperty("name"));

    }
}

resource.properties

name=Carlos

目录结果:

在这里插入图片描述

运行结果 :

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_37924905/article/details/108985465