[英]How to make custom file in Groovy
I have a text file that consists of a series of headers, each of which has a list of paths to files corresponding to that header 我有一个包含一系列标题的文本文件,每个标题都有对应于该标题的文件的路径列表
10gen
C:\cygwin\home\pro-services\git\mongodb\mongo\client\gridfs.cpp
C:\cygwin\home\pro-services\git\mongodb\mongo\client\model.cpp
10gen .SH
C:\cygwin\home\pro-services\git\mongodb\mongo\debian\mongod.1
C:\cygwin\home\pro-services\git\mongodb\mongo\debian\mongo.1
etc...
I am trying to create a new file for each of the headers, and the file will contain the related paths that are listed under the header in the original big file. 我正在尝试为每个标头创建一个新文件,并且该文件将包含原始大文件中标头下列出的相关路径。 I am a total newb to Groovy; 我对Groovy完全陌生。 how can I automate the creation these files? 如何自动创建这些文件?
Something like this: 像这样:
def output
new File("input.txt").eachLine { line ->
if (isHeader(line)) {
output?.close()
output = new PrintWriter(new FileWriter(line))
} else {
output?.println(line)
}
}
output?.close()
The isHeader
method should return true if the line is a header. 如果该行是标题,则isHeader
方法应返回true。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.