开发读取.properties 配置文件工具类PropertiesUtil

 1  
 2 
 3 import java.io.IOException;
 4 import java.io.InputStream;
 5 import java.util.Properties;
 6 
 7 import org.junit.Test;
 8 
 9 public class PropertiesUtil {
10 private static Properties p = new Properties();
11 static {
12 try {
13 p.load(PropertiesUtil.class.getClassLoader().getResourceAsStream("bitback.properties"));
14 } catch (IOException e) {
15 // TODO Auto-generated catch block
16 e.printStackTrace();
17 }
18 }
19 public static String getValue(String property){
20 return (String) p.get(property);
21 }
22 @Test
23 public static void main(String[] args){
24 System.out.println(getValue("open.host"));
25 }
26 }

 

原文地址:https://www.cnblogs.com/itworkers/p/9870782.html