How to read a file in Groovy into a string?

前端 未结 6 1378
不知归路
不知归路 2020-12-02 05:12

I need to read a file from the file system and load the entire contents into a string in a groovy controller, what\'s the easiest way to do that?

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 06:14

    A slight variation...

    new File('/path/to/file').eachLine { line ->
      println line
    }
    

提交回复
热议问题