Groovy

Groovy programming language tutorials, examples, and best practices.

Groovy Copy File – 12 Tested Examples with Multiple Approaches

Groovy copy file operations with 12 examples covering File.text, streams, NIO Files.copy(), directory copying, and backup scripts. Tested on Groovy 5.0.6. “Copying files sounds simple until you need to handle encoding, permissions, large binaries, and directory trees. That’s when your tools matter.” Last Updated: July 2026 | Tested on: Groovy 5.0.6, Java 17+ | Difficulty: Beginner to Intermediate | Reading Time: 20 minutes The groovy copy file operation seems trivial until you have to do it right. Do you need ... Read More

Groovy Create and Modify XML – MarkupBuilder, StreamingMarkupBuilder with 12 Examples

Every SOAP request, Jenkins config, and legacy data export is XML that somebody had to generate, and string concatenation breaks the moment a value contains an ampersand. This Groovy create XML guide shows the safer route: MarkupBuilder for simple documents, StreamingMarkupBuilder for namespaces and CDATA, and XmlParser with XmlUtil when you need to modify existing files. All 12 examples are tested on Groovy 5.0.6. “Writing XML by hand is like writing assembly – you can do it, but there are ... Read More

12 Groovy XmlSlurper Examples – Parse XML the Easy Way

Groovy XmlSlurper is explored here with 12 practical examples covering XML parsing, namespaces, attributes, GPath queries, and real-world patterns. Tested on Groovy 5.0.6. “XML is like violence – if it doesn’t solve your problems, you’re not using enough of it.” Last Updated: July 2026 | Tested on: Groovy 5.0.6, Java 17+ | Difficulty: Intermediate | Reading Time: 20 minutes If you’ve wrestled with DOM parsers, SAX handlers, or JAXB annotations just to pull a few values out of an XML ... Read More