读取项目中的properties文件 package com.platform.gyf.utils;import java.io.IOException;import java.io.InputStream;import java.util.Properties;//读取properties文件public class ReadProps {private static String url="";/** * 根据入参
package com.platform.gyf.utils; import java.io.IOException; import java.io.InputStream; import java.util.Properties; //读取properties文件 public class ReadProps { private static String url=""; /** * 根据入参 查询该入参对应的url * @author gyf * @param inter * @return * @throws IOException */ public static String read (String inter) throws IOException{ Properties pro = new Properties(); InputStream in; in =ClassLoader.getSystemResourceAsStream("token.properties"); // in = new FileInputStream(prop); try { pro.load(in); if(pro.containsKey(inter)){ url = pro.getProperty(inter); System.out.println(url); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return url; } public static void main(String[] args) throws IOException { String inter="token"; read(inter); } } property文件内容 token=http\:196.168.1.1/auoth/token