new Date().format("yyyy-MM-dd")
This method has been added to java.util.Date
Current date (mm/dd/yyyy) (Groovy forum at JavaRanch):
import org.codehaus.groovy.runtime.*;
class Run{
static void main(def args){
def dateTime = new Date()
println DateGroovyMethods.format(dateTime, 'MM/dd/yyyy')
}
}
Showing posts with label snippet. Show all posts
Showing posts with label snippet. Show all posts
2012-10-05
Groovy File One Liners
Groovy Scripting and Programming: Groovy File One Liners
One of the nice things about Groovy if you are a Java programmer is the ease that you can manipulate files with just one like of code.
Create or replace a file and write a line of text to it:
new File("myfile.txt").write("Here is a line: \"whats a nice programmer like you doing at a blog like this\" \n");
Append to a file (creates the if it doesn't exist)
new File("myfile.txt").append("\"Looking for a some code like this\"\n");
Read the second line (First line is line 0) of the file
println new File("myfile.txt").readLines()[1] //what was the response
One of the nice things about Groovy if you are a Java programmer is the ease that you can manipulate files with just one like of code.
Create or replace a file and write a line of text to it:
new File("myfile.txt").write("Here is a line: \"whats a nice programmer like you doing at a blog like this\" \n");
Append to a file (creates the if it doesn't exist)
new File("myfile.txt").append("\"Looking for a some code like this\"\n");
Read the second line (First line is line 0) of the file
println new File("myfile.txt").readLines()[1] //what was the response
Subscribe to:
Posts (Atom)