在groovy中读写文件
我不熟悉groovy和SOAPUI-free。我正在使用groovy脚本来驱动对SOAP UI的测试 我想写一个脚本,读取一个person ID文件,删除第一个,设置一个属性,将文件写回,而不包含我刚刚读取的文件 这是我的第一个切入点:在groovy中读写文件,groovy,soapui,Groovy,Soapui,我不熟悉groovy和SOAPUI-free。我正在使用groovy脚本来驱动对SOAP UI的测试 我想写一个脚本,读取一个person ID文件,删除第一个,设置一个属性,将文件写回,而不包含我刚刚读取的文件 这是我的第一个切入点: List pids = new ArrayList() new File("c:/dev/pids.csv").eachLine { line -> pids.add(line) } String pid = pids.get(0); testRunn
List pids = new ArrayList()
new File("c:/dev/pids.csv").eachLine { line -> pids.add(line) }
String pid = pids.get(0);
testRunner.testCase.setPropertyValue( "personId", pid )
pids.remove(0)
new File("c:/dev/pids.csv").withWriter { out ->
pids.each() { aPid ->
out.writeLine(aPid)
}
}
输出显示在soapui上,文件不会被触动。我迷路了。是的,我最后就是这么做的,只是我用了BufferedWriter。当所有其他操作都失败时,请使用Java.:)谢谢你的回复。
ArrayList pids = null
PrintWriter writer = null
File f = new File("c:/temp/pids.txt")
if (f.length() > 0){
pids = new ArrayList()
f.eachLine { line -> pids.add(line) }
println("Item to be removed: " + pids.get(0))
//testRunner.testCase.setPropertyValue( "personId", pid )
pids.remove(0)
println pids
writer = new PrintWriter(f)
pids.each { id -> writer.println(id) }
writer.close()
}
else{
println "File is empty!"
}
def myFile = new File("newfile.txt")
def newFile = new File("newfile2.txt")
//testRunner.testCase.setPropertyValue( "personId", pid )
PrintWriter printWriter = new PrintWriter(newFile)
myFile.eachLine { currentLine, lineNumber ->
if(lineNumber > 1 )
printWriter.println(currentLine)
}
printWriter.close()