【问题标题】:How to check if a directory is empty or not in Gradle?如何在 Gradle 中检查目录是否为空?
【发布时间】:2022-01-06 07:49:32
【问题描述】:

在 Java 中,我们使用下面的代码来检查目录是否为空。有人可以帮我在 Gradle 中做到这一点

private static boolean isDirEmpty(final Path directory) throws IOException {
    try(DirectoryStream<Path> dirStream = Files.newDirectoryStream(directory)) {
        return !dirStream.iterator().hasNext();
    }
}

【问题讨论】:

    标签: java gradle groovy


    【解决方案1】:

    在 gradle 中你可以简单地做file(projectDir).list().size() == 0

    【讨论】:

    • 足够说!file(projectDir).list()来检查是否为空
    猜你喜欢
    • 2018-12-23
    • 1970-01-01
    • 2019-11-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-21
    • 2018-11-20
    • 1970-01-01
    • 2016-07-14
    相关资源
    最近更新 更多