我试图读取一个文本文件并返回所有不以#开头的行.在python中我可以轻松使用列表理解列表
with open('file.txt') as f:
lines = [l.strip('\n') for l in f.readlines() if not re.search(r"^#", l)]
Run Code Online (Sandbox Code Playgroud)
我想通过Groovy完成同样的事情.到目前为止,我有以下代码,非常感谢任何帮助.
lines = new File("file.txt").readLines().findAll({x -> x ==~ /^#/ })
Run Code Online (Sandbox Code Playgroud)