How to copy files in Groovy

后端 未结 8 1691
余生分开走
余生分开走 2020-12-13 17:37

I need to copy a file in Groovy and saw some ways to achieve it on the web:

1

new AntBuilder().copy( file:\"$sourceFile.canonicalPath\", 
                  


        
8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 17:59

    I'm using AntBuilder for such tasks. It's simple, consistent, 'battle-proven' and fun.

    2nd approach is too OS-specific (Linux-only in your case)

    3rd it too low-level and it eats up more resources. It's useful if you need to transform the file on the way: change encoding for example

    4th looks overcomplicated to me... NIO package is relatively new in JDK.

    In the end of the day, I'd go for 1st option. There you can switch from copy to scp task, without re-developing the script almost from scratch

提交回复
热议问题