解析properties文件

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

/**
  * 返回Properties文件中的值
  * @param fileName文件路径
  * @param key文件中key名称
  * @return
  */
public class PropertyUtil { public static String getValueFromFile(String fileName,String key){ Properties properties = new Properties(); ClassLoader loader=Thread.currentThread().getContextClassLoader(); URL propertiesUrl=loader.getResource(fileName); try { InputStream in = propertiesUrl.openStream(); properties.load(in); } catch (IOException e) { e.printStackTrace(); } String value = properties.getProperty(key); return value;   } }

  

原文地址:https://www.cnblogs.com/rmsSpring/p/Properties.html