-1

I have a text file contains 45 lines. I need to read the text file line by line based on the counter increment function.

Example: If we read the first line of a line then it prints count value is 1 and so on...

please provide me some good examples.

chinna
  • 55
  • 1
  • 8

2 Answers2

1

Try this:

new File(filename).eachWithIndex() { line, idx ->
    log.info "${idx} : ${line}"
}
ou_ryperd
  • 2,037
  • 2
  • 18
  • 23
  • I have an A method calling from the main method. when the main method calls A method the first time it should print the first line from the text file. when A method calls the second time it should print the second line and so on – chinna May 28 '20 at 10:52
0
  • new File('/path/to/your/file').readLines().get(0) - returns the first line of the file
  • new File('/path/to/your/file').readLines().get(1) - returns the second line of the file
  • etc.

If you need to access the JMeter variable defined by the Counter configuration element - use vars shorthand for JMeterVariables class instance like:

new File('/path/to/your/file').readLines().get(vars.get('your_counter_variable') as int))

More information:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133