0
votes

I tried to convert the jmeter .jtl file to csv file. Each line of jtl file contains the variables separated by commas as in normal csv file. For example: a,b,c,d,e,f However, in some of the lines there are multiple delimiter like comma(,) and comma inside quotation(","). For example : a,b,"c,d",e,f I could parse the comma separated value easily by reading the jtl file . But when I encounter comma inside quotation delimiter, by code fails to generate the useful result. I tried to use java multi split , but still the problem persists.

My java code is as follows :

try{
 BufferedReader reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(new File("D:/apache-jmeter-2.11/apache-jmeter-2.11/bin/")))));
while((line = reader.readLine()) !=null){   
    String[] datas = line.split("[,\",\"]");
     p.println(datas[0] + "," + datas[5] + "," + datas[2] + "," + datas[1] + "," + datas[3] + "," + datas[8] + "," + datas[9]); 
}

I have used split to split using (,)and (","). How shoud i rewrite the code so that the problem could be solved.

3
any feedback on my answer ? - UBIK LOAD PACK

3 Answers

1
votes

Use uniVocity-parsers to read this:

CsvParserSettings settings = new CsvParserSettings(); //many options to configure the format and the parser here. Check the tutorial
CsvParser parser = new CsvParser(settings);
List<String[]> allRows = parser.parseAll(
    new FileReader(new File("D:/apache-jmeter-2.11/apache-jmeter-2.11/bin/")));

Disclosure: I am the author of this library. It's open-source and free (Apache V2.0 license).

0
votes

For me what you are looking for is an existing CSV processing library that you can make use of. I use OpenCSV with success to process JMeter output, but this is obviously just one of many possible options.