Skip to content

Instantly share code, notes, and snippets.

@irof
Created November 5, 2011 11:27
Show Gist options
  • Select an option

  • Save irof/1341409 to your computer and use it in GitHub Desktop.

Select an option

Save irof/1341409 to your computer and use it in GitHub Desktop.
ファイルのコピーをいくつか
// ファイルコピー
// まずコピー元ファイルを作成
def src = new File('src.txt')
src.text = 'jggugcamp2011'
"chmod 777 src.txt".execute()
// readBytes
new File('dest.txt') << new File('src.txt').getBytes()
// AntBuilder
new AntBuilder().copy(file:'src.txt', tofile:'dest_ant.txt');
// execute(反則)
'cp src.txt dest_execute.txt'.execute()
// NIO2.0
// JavaSE7互換
import java.nio.file.*;
Files.copy(Paths.get("src.txt"), Paths.get("dest_nio2_1.txt"));
Files.copy(Paths.get("src.txt"), Paths.get("dest_nio2_2.txt"), StandardCopyOption.COPY_ATTRIBUTES);
@irof

irof commented Nov 5, 2011

Copy link
Copy Markdown
Author

属性はこんな感じに。

total 56
drwxr-xr-x 9 irof staff 306 11 5 20:26 .
drwxr-xr-x 4 irof staff 136 11 5 20:12 ..
-rw-r--r-- 1 irof staff 13 11 5 20:26 dest.txt
-rw-r--r-- 1 irof staff 13 11 5 20:26 dest_ant.txt
-rwxr-xr-x 1 irof staff 13 11 5 20:26 dest_execute.txt
-rwxr-xr-x 1 irof staff 13 11 5 20:26 dest_nio2_1.txt
-rwxrwxrwx 1 irof staff 13 11 5 20:26 dest_nio2_2.txt
-rw-r--r-- 1 irof staff 581 11 5 20:25 filecopy.groovy
-rwxrwxrwx 1 irof staff 13 11 5 20:26 src.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment