读取项目中相对目录

public class ReadConfig { 

private static String readValueByKey(String filePath,String key){
       Properties props = new Properties();
    InputStream in = ReadConfig.class.getResourceAsStream(filePath);
    try {
     props.load(in);
    } catch (IOException e1) {
     System.out.println("+++++++++++++++++++++++++++++++++++++");
     System.out.println("\n\n");
     System.out.println("请检查文件是否在当前目录中 "+filePath+" 然后重新调用。");
     System.out.println("\n\n");
     System.out.println("+++++++++++++++++++++++++++++++++++++");
     // TODO 自动生成 catch 块
     e1.printStackTrace();
     return null;
    }
          String value = props.getProperty (key);
          //System.out.println("++++++++++++++ "+value);
          return value;
          
  
  }

}

filePath 文件和当前class在同一个目录中。 
 

你可能感兴趣的:(读取)