how to replace a string/word in a text file in groovy

前端 未结 6 2234
难免孤独
难免孤独 2020-12-05 22:57

Hello I am using groovy 2.1.5 and I have to write a code which show the contens/files of a directory with a given path then it makes a backup of the file and replace a word/

6条回答
  •  鱼传尺愫
    2020-12-05 23:33

    other simple solution would be following closure:

    def replace = { File source, String toSearch, String replacement ->
            source.write(source.text.replaceAll(toSearch, replacement))
        }
    

提交回复
热议问题