zoukankan      html  css  js  c++  java
  • getResourceAsStream properties

     try (InputStream is = getClass().getResourceAsStream("/test.properties")) {
          Properties properties = new Properties();
          properties.load(is);
          ps=new PropertiesPropertySource("main", properties);
        } catch (IOException e) {
          log.error("Something went wrong", e);
        }
     private String getPomPerpertiesPath() {
        String classPath = getClass().getClassLoader().getResource("").getPath();
        String aString = "classes/";
        String targetPath = classPath.substring(0, classPath.lastIndexOf(aString));
        StringBuilder sb = new StringBuilder();
        sb.append(targetPath).append("maven-archiver/pom.properties");
        return sb.toString();
      }*/
      private Properties getProperties(InputStream is) throws IOException {
        Properties properties = new Properties();
        properties.load(is);
        log.info("All defined properties: {}", properties);
        return properties;
      }
      private Properties getProperties(String fileName) throws IOException {
        try (InputStream is = new FileInputStream(new File(fileName))) {
          Properties properties = new Properties();
          properties.load(is);
          log.info("All defined properties: {}", properties);
          return properties;
        }
     System.out.println(getClass().getClassLoader().getResource(""));
     System.out.println(getClass().getClassLoader().getResource("").getPath());
     System.out.println(getClass().getResource(""));
     System.out.println(getClass().getResource("").getPath());
    
    file:/C:/Users/lt32806/git/tempest/tempest-app/tempest-app-report/target/classes/
    /C:/Users/lt32806/git/tempest/tempest-app/tempest-app-report/target/classes/
    file:/C:/Users/lt32806/git/tempest/tempest-app/tempest-app-report/target/classes/com/citi/simpliciti/tempest/report/
    /C:/Users/lt32806/git/tempest/tempest-app/tempest-app-report/target/classes/com/citi/simpliciti/tempest/report/

    https://blog.csdn.net/wws921104/article/details/72637050/
    http://riddickbryant.iteye.com/blog/436693

  • 相关阅读:
    使用相对路径名导入包中子模块
    python中子类使用父类属性
    快速掌握Java8 Stream函数式编程技巧
    灵感来袭,基于Redis的分布式延迟队列(续)
    寻找最长不含有重复字符的子串 示例
    golang学习笔记---函数示例
    golang学习笔记---逐行读取文件示例
    golang学习笔记---int转二进制示例
    golang学习笔记---iota(枚举自增值)
    golang学习笔记 ----container/list包用法
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/9469899.html
Copyright © 2011-2022 走看看