读取配置文件ProPertiesUtil

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ProPertiesUtil {
	public static String getValue(String path,String key) {
		String value = "";
		try {
			Properties properties = new Properties();
			InputStream inputStream = ProPertiesUtil.class.getResourceAsStream(path);
			properties.load(inputStream);
			if(properties.containsKey(key)){
				value = properties.getProperty(key);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return value;
	}
	
	
	public static void main(String[] args) {
		System.out.println(ProPertiesUtil.getValue("/server.properties", "serverUrl"));
	}
}

 

你可能感兴趣的:(properties)