java 读取properties文件

 

import java.io.IOException;

import java.io.InputStream;

import java.util.Properties;



public class GetProperties {

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

        Properties p = new Properties();

        InputStream in = GetProperties.class

                .getResourceAsStream("/config.properties");
        p.load(in);

        in.close();

        System.out.println(p.getProperty("ip"));

    }

}

 

image

javaweb工程编译后,config.properties在classes文件夹下

image

你可能感兴趣的:(properties)