1、项目结构及配置文件内容

java 配置jar包 java打成jar包配置文件不在_java

 

 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、执行结果

java 配置jar包 java打成jar包配置文件不在_System_02

 

 4、执行jar包

java 配置jar包 java打成jar包配置文件不在_System_03