Here is a great example of how Groovy is so much less verbose than Java.

The script below is a simple utility I wrote that encrypts a directory of files using GPG. The command.execute() syntax in groovy is so much less verbose than the Java counterpart.

def fileEncrypter(srcFolder, destFolder)
{
	new File(destFolder).eachFile{file ->
		println "Deleting File: " + file.absolutePath
		file.delete()
	}
 
	new File(srcFolder).eachFile{file ->
		String command = "gpg -e -o "
		command += destFolder + "/" + file.name
		command += ".pgp -r "My Key" --yes -q "
		command += srcFolder + "/" + file.name
		println "Encrypting file: " + file.absolutePath
		command.execute().text
	}
}

Tags: ,