加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

在groovy中读写文件

发布时间:2020-12-14 16:25:41 所属栏目:大数据 来源:网络整理
导读:我是groovy和SOAP UI的新手.我正在使用一个groovy脚本来驱动我对SOAP UI的测试. 我想编写一个脚本来读取人员ID文件,删除第一个文件,设置属性,将文件写回来,而不是我刚读过的文件. 这是我的第一次切入: List pids = new ArrayList()new File("c:/dev/pids.cs
我是groovy和SOAP UI的新手.我正在使用一个groovy脚本来驱动我对SOAP UI的测试.

我想编写一个脚本来读取人员ID文件,删除第一个文件,设置属性,将文件写回来,而不是我刚读过的文件.

这是我的第一次切入:

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)
    }
}

输出显示在SOAP UI上,文件不会被触及.我迷路了.

解决方法

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!"
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读