1
我在Soapui有一个项目和一个运行项目所有测试的groovy代码。 结果可以在输出控制台中看到。 所以我想要的是保存输出ina文件的内容。Groovy如何将控制台输出保存到文件?
在Java中,我们可以这样做:
//create a buffered reader that connects to the console, we use it so we can read lines
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//read a line from the console
String lineFromInput = in.readLine();
//create an print writer for writing to a file
PrintWriter out = new PrintWriter(new FileWriter("c:/temp7/output.txt"));
//output to the file a line
out.println(lineFromInput);
//close the file
out.close();
是否有一个等效代码在Groovy? 谢谢您
我相信你会从soapui工具运行该项目。对?但是为了收集输出,你在哪里运行上面的java代码呢?顺便说一句,相同的代码应该也适用于常规。 – Rao 2015-01-26 18:06:22
我在所有测试结束时从groovy步骤运行此代码。我尝试了相同的代码,但我有错误,它应该是这样的def file = new File('c:/temp7/sample.txt') file.withWriter('UTF-8'){ it.writeLine '将此文字添加到文件中。' }在这里,我应该添加控制台输出的内容。 – 2015-01-26 18:09:35
你的意思是说,该项目是从一个groovy步骤本身运行? – Rao 2015-01-26 18:12:43