Groovy

Home » Groovy

Escape HTML Characters in Groovy

To escape HTML characters in Groovy, you can use the StringEscapeUtils.escapeHtml() method from the org.apache.commons.lang3 library. Here's an example: Escape HTML Characters in Groovy using StringEscapeUtils Example import org.apache.commons.lang3.StringEscapeUtils def str = "<p>Hello world!</p>" def escapedStr = StringEscapeUtils.escapeHtml(str) println escapedStr This code escapes the HTML characters in the string str. The output will be: &lt;p&gt;Hello …

Escape HTML Characters in Groovy Read More »

Check if File Exists in Groovy

To check if a file exists in Groovy, you can use the new File(<file_name>).exists() method. Here's an example: def fileName = "myfile.txt" if (new File(fileName).exists()) { println "$fileName exists" } else { println "$fileName does not exist" } This code checks if a file named myfile.txt exists in the current directory. If it does, it …

Check if File Exists in Groovy Read More »