grails - 使用groovy替换文件中的字符串

标签 grails groovy groovyshell

我有一个名为“silent.txt”的文件。该文件的行如下

bop4InstallDir = myProps.cordys_install_dir + "/" + instanceName

我想将上面的文本替换为
bop4InstallDir = "/abc/xyz/pqr"

使用groovy脚本我该如何完成?
请帮忙。

最佳答案

不是很优雅,但这应该可行。

def file = new File("silent.txt")

file.text = file.text.replace('bop4InstallDir = myProps.cordys_install_dir + "/" + instanceName', 
'bop4InstallDir = "/abc/xyz/pqr"')

关于grails - 使用groovy替换文件中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21670269/

相关文章:

java - 避免在不同的 Groovy 脚本之间共享 Java 元类

grails - 在 Grails 插件中访问资源

mongodb - GORM-使用mongoDB时似乎会忽略唯一约束

grails - 失败:生成失败,出现异常

grails - 贝壳和瓶盖

grails - Spock 不使用 Groovy MetaClass 对被测服务的更改

binding - 如何使用 GroovyShell 列出所有绑定(bind)变量

sql - Groovy DSL for Liquibase中的自定义SQL?

Java/Groovy - 字符串 : replace characters on matched regex

groovy - 如何将方法作为 Binding 变量传递给 Groovy 的 ConfigSlurper?