0
在grails中,我们可以在脚本中重定向打印方法并使用GroovyShell
运行,如下所示。如何在grails中使用脚本覆盖所有打印方法的功能
def scriptText = '''
def s = "Groovy rocks!"
println s
printf 'The answer is %X', 42
'''
def shell = new GroovyShell()
def script = shell.parse(scriptText)
def stringWriter = new StringWriter()
script.out = new PrintWriter(stringWriter)
script.run()
assert stringWriter.toString() == 'Groovy rocks!\nThe answer is 2A'
,但我想使打印的输出到一个文件并执行的println,printf的默认功能或调用println etc.Please帮助我。