【问题标题】:How to save output from groovyconsole in a file?如何将 groovyconsole 的输出保存在文件中?
【发布时间】:2018-06-14 01:47:33
【问题描述】:

我已经在 AEM 中安装了 groovyconsole,并且有一堆我想保存在文件中作为输出的东西。

this 的帖子之后,我尝试了:

def filePath = "/content/corporate/reports/output.csv"
File output = new File(filePath)

output.append('Hello world!')

我最终得到一个 FileNotFoundException。我直接创建文件只是为了确保,但这也无济于事。

不胜感激。谢谢。

【问题讨论】:

  • 看起来您正在使用 JCR 路径(节点路径)。使用 File 表示“文件系统”上的文件,而不是 JCR 路径(节点路径)。您是否要保存到 JCR?如果是这样,那就是不同的 API

标签: groovy aem groovy-console


【解决方案1】:

我建议您检查以下内容:

  • 您可能没有写入指定文件夹的权限。您应该先尝试写入您绝对具有写入权限的文件夹。
  • 可能不是所有指向 output.csv 的目录都存在,您应该使用File.mkdirs() 确保文件夹树存在,如下所示:

def folderPath = "~/fff/eee/reports"
def folder = new File(folderPath)
def result =folder.mkdirs()

def filePath = "~/fff/eee/reports/output.csv"
File output = new File(filePath)

output.withWriterAppend{ out ->
    out.println 'hello there!'
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-25
    • 1970-01-01
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多