File 什么';这是一个“经典的”;将文件1追加到文件2“中”;groovy代码片段?
我已经搜索了Google&the,但还没有找到标准的方法:File 什么';这是一个“经典的”;将文件1追加到文件2“中”;groovy代码片段?,file,groovy,File,Groovy,我已经搜索了Google&the,但还没有找到标准的方法: cat a.txt b.txt > c.txt 在groovy中。这里有一个建议: def appendFile(File src, File target) { def newline = System.getProperty('line.separator') src.eachLine { line -> target << line target <
cat a.txt b.txt > c.txt
在groovy中。这里有一个建议:
def appendFile(File src, File target) {
def newline = System.getProperty('line.separator')
src.eachLine { line ->
target << line
target << newline
};
}
def appendFile(文件src,文件目标){
def newline=System.getProperty('line.separator')
src.eachLine{line->
target如果将InputStream传递给,它会将流的内容附加到文件中。我会执行以下操作:
src.withInputStream { input ->
target << input
}
src.withInputStream{input->
target会让FileInputStream挂起吗?最好是(假设target
和src
是文件):src.withReader{target AReader
根据编码解释字符。除非您特别需要处理文本编码,InputStream
在这里可能更有意义。我认为每次都是@ripper?它一次完成整个文件