1、项目结构及配置文件内容
2、配置文件内容读取 代码实现
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
public class TestResource
{
public static void main(String[] args)
{
TestResource t=new TestResource();
t.test();
}
public void test()
{
InputStream in = TestResource.class.getClass().getResourceAsStream("/resource/config.properties");
BufferedReader reader = null;
try
{
reader = new BufferedReader(new InputStreamReader(in,"UTF-8"));
}
catch (UnsupportedEncodingException e1)
{
e1.printStackTrace();
}
Properties p = new Properties();
try
{
p.load(reader);
}
catch (IOException e)
{
e.printStackTrace();
}
System.out.println(p.getProperty("name"));
System.out.println(p.getProperty("name1"));
//System.out.println(p.getProperty("excelPath").toString().trim());
//System.out.println(p.getProperty("driverPath").toString().trim());
}
}
3、执行结果
4、执行jar包