Last active
December 11, 2015 18:08
-
-
Save koji-k/4638993 to your computer and use it in GitHub Desktop.
This file contains 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 fileName = "/tmp/groovy_io_sample.txt" | |
def encode = "UTF-8" | |
def file = new File(fileName) | |
// 存在確認 | |
if (file.exists()) { | |
println "not exists" | |
} else { | |
println "not exists" | |
} | |
// write | |
file.withWriterAppend(encode) {it << "ABCDEFG"} | |
file.append("HIJKLMN",encode) | |
// read pattern 1 | |
file = new File(fileName) | |
file.eachLine(encode){println it} | |
// read pattern 2 | |
file = new File(fileName) | |
println file.getText(encode) | |
// read pattern 3 | |
file = new File(fileName) | |
println file.newReader(encode).text | |
// ファイルの削除 | |
file.delete() | |
// ファイルが削除されている事を確認 | |
assert file.exists() == false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment