(1) 一般文字檔
new File(your_source_file).withReader { rdr -> new File(your_destination_file).withWriter { wtr -> rdr.readLine { line -> wtr << line } } }(2) Binary 檔案
def fos = null def fis = null try { fos = new FileOutputStream(your_destination_file) fis = new FileInputStream(your_source_file) fos << fis finally { try { fos?.close() } catch(e) { /*ignore*/ } try { fis?.close() } catch(e) { /*ignore*/ } }(3) 用 ANT utility
new AntBuilder().copy(file: your_source_file, tofile: your_destination_file)三者各有各的使用情境。
沒有留言:
張貼留言