Created
November 5, 2011 11:27
-
-
Save irof/1341409 to your computer and use it in GitHub Desktop.
ファイルのコピーをいくつか
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ファイルコピー | |
| // まずコピー元ファイルを作成 | |
| 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); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
属性はこんな感じに。
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