我需要从文件系统中读取一个文件并将整个内容加载到 groovy Controller 中的字符串中,最简单的方法是什么?
最佳答案
String fileContents = new File('/path/to/file').text
如果您需要指定字符编码,请改用以下内容:
String fileContents = new File('/path/to/file').getText('UTF-8')
关于file - 如何将 Groovy 中的文件读入字符串?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7729302/