IDEA读取配置文件

IDEA读取配置文件

package cn.ssx.test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;

/**
 * Created by shao on 2019/5/14.
 */

    public class test {
            public static void main(String[] args) throws FileNotFoundException,IOException {
                Properties properties = new Properties();
                //设置配置文件路径
                String path = test.class.getClassLoader().getResource("test.properties").getPath();  
                properties.load(new FileInputStream(path));
                /*System.out.println(properties.getProperty("lisi"));
                System.out.println(properties.getProperty("zhangsan"));*/
                Enumeration enuml = properties.propertyNames();
                while(enuml.hasMoreElements()) {
                                String strKey = (String) enuml.nextElement();
                                 String strValue = properties.getProperty(strKey);
                                System.out.println(strKey + "=" + strValue);
                             }
            }
        }




你可能感兴趣的:(IDEA读取配置文件)