【问题标题】:Intellij not able to identify root folder when SBT build is used使用 SBT 构建时 Intellij 无法识别根文件夹
【发布时间】:2021-11-22 05:40:45
【问题描述】:

下面是我的项目结构。我试图在下面的程序中读取我的属性文件pgmproperties.properties,但收到错误File Not found。请告诉我我应该把我的文件放在哪里。我正在使用 SBT 构建工具。

我的代码

def main(args: Array[String]) {
    // This is used to read Properties files and get the values
    val is: InputStream = ClassLoader.getSystemResourceAsStream("pgmproperties.properties")
    val prop: Properties = new Properties()
    if (is != null) {
      prop.load(is)
    }
    else {
      throw new FileNotFoundException("Properties file cannot be loaded")
    }
    val sndrmailid = prop.getProperty("SndrMailId")      //Sender Mail id
    val psswd      = prop.getProperty("SndrMailPsswd")   //Sender gmail Mailbox id password
    val tomailid   = prop.getProperty("RcvrMailId")      // Receiver email id.

     println( sndrmailid )   
  }

获取错误

【问题讨论】:

    标签: scala apache-spark intellij-idea


    【解决方案1】:

    正确的放置资源的地方是:src/main/resources(正如官方SBT中所说的documentation)。 尝试将您的文件移到那里,它应该可以工作:)

    【讨论】:

    • 它不工作。
    • 是的,但 OP 也必须不使用 getSystemResourceAsStream 来支持常规的 getResourceAsStream
    猜你喜欢
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 2021-01-03
    • 2019-10-03
    • 1970-01-01
    • 2021-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多