逐行读取文件并通过Groovy重新创建文件

逐行读取文件并通过Groovy重新创建文件,groovy,readfile,Groovy,Readfile,我有一个文本文件,格式如下: VER -------------------------------------------------------------------------------- somelines here somelines here

我有一个文本文件,格式如下:

VER                                                                             
--------------------------------------------------------------------------------
somelines here  
somelines here                                                          
VER                                                                             
--------------------------------------------------------------------------------
somelines here  
somelines here  
somelines here            
我想通过groovy创建不包含VER,----和空行的新文件,这是我的代码:

new File("C:/L_Groovy/L-Groovy/outmap.txt") << new File("C:/L_Groovy/L-Groovy/maps.txt").filterLine { !it.contains("VER") && !it.contains ("--") && ??? }

新文件(“C:/L\u Groovy/L-Groovy/outmap.txt”)以下约束应该是有用的:

 !it.trim().isEmpty() 

尝试!it.trim().isEmpty()非常感谢,它工作了,但我还有一个问题,在新文件的末尾,它有空单词。有没有办法让我删除它?谢谢!将其添加为答案-请接受。不知道null来自哪里。请提供一个完整的例子。也许
!null
会有帮助吗?非常感谢,如果我想在每行末尾添加.xml,您能帮助我吗。我可以用groovy来做吗?也许可以。但这是另一个问题——在不同的帖子中提问。