If you just need the entire line from a text file, you can do something like the following:
1. Create a DataSource as a Data Generator for random integers to use as the line number
2. Create a Groovy Script step that reads the line from the file:
String readLine( File f, int n ) {
String line = null;
f.withReader { r ->
while( n-- > 0 && ( ( line = r.readLine() ) != null ) ) ;
}
return line;
}
def lineNum = context.expand('${Get Random Line Number#lineNum}') as Integer;
File infile = new File("C:\\local\\files\\lesmis.txt")
String line = readLine(infile, lineNum )
log.info("$lineNum: $line");
return line;
3. Create a DataSource Loop step that points back to the Groovy Script step.
4. Put your steps between the Groovy Script step and the DataSource Loop, referencing the Groovy Script step result property:
${Get Random Row#result}
This method reads every row in the file up to the selected one each time through, so it will be slower on larger files, but does not require loading all rows into memory. 1000 reads from a 50000 line file took about 15 seconds to complete.