Skip to content

Instantly share code, notes, and snippets.

@ppazos
Forked from js1972/write_file.groovy
Created March 25, 2024 18:31
Show Gist options
  • Save ppazos/2fa2046701354ffa20447d8c28e6f796 to your computer and use it in GitHub Desktop.
Save ppazos/2fa2046701354ffa20447d8c28e6f796 to your computer and use it in GitHub Desktop.
How to write content to a new file (overwrite if already existing) in Groovy.
//
// Write the mock request payload to a file for checking later...
// newWrite() is the important it to ensure you get a *new* file each time.
//
def filename = "C:\\MyScratchFolder\\soapUI projects\\Testing\\procon\\mock_po_activity_request.xml"
def file = new File(filename)
def w = file.newWriter()
w << mockRequest.requestContent
w.close()
@ppazos
Copy link
Author

ppazos commented Mar 25, 2024

file.newWriter().withWriter { w ->
w << mockRequest.requestContent
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment