Groovy:如何加载属性文件并处理“找不到文件”的情况?

时间:2018-12-10 11:59:08

标签: groovy

我正在使用以下代码加载属性文件:

    File propertiesFile = new File(PROPS_FILE_PATH)
    Properties workflowProperties = new Properties()
    propertiesFile.withInputStream {
        workflowProperties.load it
    }

这很好。 但是我无法处理文件不存在的情况。 正确的方法是什么? 捕获FileNotFoundException或任何其他异常对我不起作用。

谢谢。

1 个答案:

答案 0 :(得分:0)

您应该检查文件是否存在:

File propertiesFile = new File(PROPS_FILE_PATH)
if( !propertiesFile.exists() ) throw new Exception( 'File not found' ) // bail out
相关问题