【问题标题】:cannot read file.properties from resource file无法从资源文件中读取 file.properties
【发布时间】:2014-07-14 14:10:06
【问题描述】:

我创建了一个使用 Meta-Inf/config.properties 文件的 jar 文件!! 问题是我想从资源文件而不是 jar 文件中使用 Meta-Inf/config.properties 我试过这个

InputStream input =  classLoader.getResourceAsStream("META-INF/config.properties");

但是这一行从 jar 而不是从资源文件中读取 config.properties 文件!! 我也试过类似的东西:

InputStream input =  classLoader.getResourceAsStream("classpath:META-INF/config.properties");

但什么都没有 任何想法

  • 资源文件:只是目录src/main/resources

【问题讨论】:

    标签: java jakarta-ee classloader inputstream fileinputstream


    【解决方案1】:

    获取资源的方式:

    String pathToPropertyFile = "resources/META-INF/config.properties";
    InputStream stream= ClassName.class.getResourceAsStream(pathToImage );
    

    或者

       String pathToPropertyFile = "resources/META-INF/config.properties";
       InputStream stream= ClassName.class.getResource(pathToImage );
    

    假设scr/main/resources/下有一个名为META-INF的文件夹

    【讨论】:

      猜你喜欢
      • 2014-06-07
      • 2011-10-12
      • 2018-11-12
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      • 2016-06-17
      • 2023-03-24
      • 1970-01-01
      相关资源
      最近更新 更多