公告版位

目前分類:Groovy (3)

瀏覽方式: 標題列表 簡短摘要

// write file - overwrite
def filename = "/tmp/text1.txt"
def file = new File(filename)
def w = file.newWriter()

w << "Hello World!"
w.close()

// read file
String r = new File('/tmp/text1.txt').text
println(r)

============= Output =============
Hello World!

dreamtails 發表在 痞客邦 留言(0) 人氣()

import java.io.File;

File theFile = new File("/tmp/text1.txt");
println("Dirname: " + theFile.getParent());
println("Basename: " + theFile.getName());

============== Output ==============
Dirname: /tmp
Basename: text1.txt

dreamtails 發表在 痞客邦 留言(0) 人氣()

import java.io.File;

File f = new File("/tmp/text1.txt");
if(f.exists() && !f.isDirectory()) { 
    println("${f.path} - This is a File!")
}

============= Output ===============
/tmp/text1.txt - This is a File!

dreamtails 發表在 痞客邦 留言(0) 人氣()