I am trying to read a file line by line and then creating a new file from each line(except last line). For example if filename is object then new files will be object1 object2 ..so on. I am not able to use writeFile method because i am inside a NonCPS method and my agent is a jenkins slave. And also File class is not working because of Groovy DSL limitations. Is there any other way to achieve this. Here is my code, there is no problem with the code so far but nothing is working.
@NonCPS
def createFile(String[] paths, NoOfLines)
{
String[] names = ["object1", "object2", "object3"]
for(int j=0; j<=2; j++)
{
int count=1
new File("/data/jenkins/workspace/project1/"+paths[j]).eachLine
{
line -> def newFile = new File("/data/jenkins/workspace/project1/"+names[j]+count+".json")
newFile.write(line)
if (count == NoOfLinesp[j])
{
newFile.delete()
}
count++
}
}
}