package day2;
import org.junit.Test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;
public class ClassLoaderDemo1 {
@Test
public void test1() throws Exception {
Properties props=new Properties();
//默认路径:当前项目下
//FileInputStream fis=new FileInputStream("jdbc.properties");
//props.load(fis);
//用ClassLoader读取配置文件
//默认路径:src下
ClassLoader loader=ClassLoaderDemo1.class.getClassLoader();
InputStream is = loader.getResourceAsStream("jdbc1.properties");
props.load(is);
String user=props.getProperty("user");
String password=props.getProperty("password");
System.out.println("user:"+user+",password:"+password);
}
}
标签:java,读取,配置文件,ClassLoader,user,props,import,password From: https://www.cnblogs.com/fighterk/p/16939249.html