Skip to content

Instantly share code, notes, and snippets.

@alder
Created January 12, 2015 16:04
Show Gist options
  • Save alder/1420a45c19cb947e03ce to your computer and use it in GitHub Desktop.
Save alder/1420a45c19cb947e03ce to your computer and use it in GitHub Desktop.
Manually read CSV data in JMeter witn BeanShell
import java.text.*;
import java.io.*;
import java.util.*;
String filename = "oprosnik_" + vars.get("fileNum") + ".csv";
ArrayList strList = new ArrayList();
try {
File file = new File(filename);
if (!file.exists()) {
throw new Exception ("ERROR: file " + filename + " not found");
}
BufferedReader bufRdr = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8"));
String line = null;
Integer i = 0;
while((line = bufRdr.readLine()) != null) {
strList.add(line);
i++;
}
bufRdr.close();
counter = Integer.parseInt(vars.get("counter"));
if (counter != i) {
String[] variables = strList.get(counter).split(",");
vars.put("answer",variables[0]);
vars.put("answerNum",variables[1]);
counter++;
vars.put("counter",Integer.toString(counter));
}
else {
vars.put("answer","<EOF>");
vars.put("eol","<EOF>");
vars.put("counter","0");
}
}
catch (Exception ex) {
IsSuccess = false;
log.error(ex.getMessage());
System.err.println(ex.getMessage());
}
catch (Throwable thex) {
System.err.println(thex.getMessage());
}
@jagadeeshvenkatesh
Copy link

hi Thanks for the beahshell .. what is counter value ?
counter = Integer.parseInt(vars.get("counter"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment