Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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()
@llehtinen

This comment has been minimized.

Copy link

@llehtinen llehtinen commented Jul 22, 2015

This helped me today :) Make it ever groovier (closes writer for you):

file.newWriter().withWriter {
  w << mockRequest.requestContent
}
@ruoguluo

This comment has been minimized.

Copy link

@ruoguluo ruoguluo commented Oct 11, 2015

thank you!

@esmiralha

This comment has been minimized.

Copy link

@esmiralha esmiralha commented Jan 24, 2016

Small typo above:

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

This comment has been minimized.

Copy link

@dilan85desilva dilan85desilva commented Sep 8, 2016

Yes yes yes, Thank You !

@mangan77

This comment has been minimized.

Copy link

@mangan77 mangan77 commented Feb 13, 2017

Thanks a lot!

@martinkbrown

This comment has been minimized.

Copy link

@martinkbrown martinkbrown commented Mar 10, 2017

Works. Thanks!

@DenverKen

This comment has been minimized.

Copy link

@DenverKen DenverKen commented Oct 18, 2017

I"m a Groovy newb and this was really helpful to me, thanks!

@gezerk

This comment has been minimized.

Copy link

@gezerk gezerk commented Jan 6, 2018

Nice! This was a great help. The comments were super useful too.

@fadyboy

This comment has been minimized.

Copy link

@fadyboy fadyboy commented Mar 28, 2018

This helped me too, thanks a lot

@sateesharv

This comment has been minimized.

Copy link

@sateesharv sateesharv commented Aug 10, 2018

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.