groovy - 如何将 groovyconsole 的输出保存在文件中?
问题描述
我已经在 AEM 中安装了 groovyconsole 并且有一堆我想保存在文件中作为输出的东西。
在这篇文章之后,我尝试了:
def filePath = "/content/corporate/reports/output.csv"
File output = new File(filePath)
output.append('Hello world!')
我最终得到一个 FileNotFoundException。我直接创建文件只是为了确保,但这也无济于事。
希望对此有所了解。谢谢。
解决方案
我建议您检查以下内容:
- 您可能没有写入指定文件夹的权限。您应该首先尝试写入您绝对具有写入权限的文件夹。
- 可能并非所有导致 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!'
}
推荐阅读
- c# - 负前瞻行为不符合预期
- java - 三元运算符中不需要的 NullPointerException - 为什么?
- java - 通信链路故障(MYSQL SERVER 8 + JAVA)
- python - 需要从下拉菜单中单击一个文本来更改下拉菜单中的默认选项
- django - Django 对象唯一性地狱与 M2M 字段
- angular - *ngFor keyvalue descOrder 不适用于日期
- python - 未找到非 root 用户命令
- string - 为什么在获取和显示字符串中的字符时会得到意外结果?
- haskell - Replacing do by >>= for a scotty post
- python - 如何使 Python argparse 正确解释与命令匹配的参数?