小智 12
实际上这很容易:
String[] words = new File('words.txt')
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用:
def words = new File('words.txt') as String[]
Run Code Online (Sandbox Code Playgroud)
tim*_*tes 11
怎么样:
def words = []
new File( 'words.txt' ).eachLine { line ->
words << line
}
// print them out
words.each {
println it
}
Run Code Online (Sandbox Code Playgroud)