I have file contents in a java string variable, which I want to convert it into a File object is that possible?
public void setCfgfile(File cfgfile)
{
this.cfgfile = cfgfile
}
public void setCfgfile(String cfgfile)
{
println "ok overloaded function"
this.cfgfile = new File(getStreamFromString(cfgfile))
}
private def getStreamFromString(String str)
{
// convert String into InputStream
InputStream is = new ByteArrayInputStream(str.getBytes())
is
}
As this is Groovy, you can simplify the other two answers with:
Which will return a file handle to the file it just wrote
contentinto