Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 什么';这是一个“经典的”;将文件1追加到文件2“中”;groovy代码片段?_File_Groovy - Fatal编程技术网

File 什么';这是一个“经典的”;将文件1追加到文件2“中”;groovy代码片段?

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 <

我已经搜索了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 << 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 A
Reader
根据编码解释字符。除非您特别需要处理文本编码,
InputStream
在这里可能更有意义。我认为每次都是
@ripper?它一次完成整个文件