Groovy Script : Text File Create & Write.
def fileName = "test1.txt"
// Defining a file handler/pointer to handle the file.
def inputFile = new File("d:\\"+fileName)
// Check if a file with same name exisits in the folder.
if(inputFile.exists())
{
// if a file exisits then it will print the message to the log.
log.info("A file named " + fileName + " already exisits in the same folder")
}
else
{
//else it will create a file and write the text "Hello World !"
inputFile.write("Hello World !")
log.info "File got created"
}
No comments:
Post a Comment