title: Results are not stored with a column names in CSV file after running the Jmeter test through a program (Java Code)
body: <p>I have successfully run the Jmeter test using a program i.e written in java code. And I am sharing the link of that question's solution here as well => <a href="https://stackoverflow.com/q/59841310/12434952">How to set CSV file in java code by running the Jmeter test using a program (Java Code)?</a></p>
  
  <p><strong>Now, I got the results in my CSV file but the problem in that file is, it is not showing the column names, it just fetched the results and store it into the file. Please refer to the below picture for more information.</strong></p>
  
  <p><a href="https://i.stack.imgur.com/F5cC0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F5cC0.png" alt="enter image description here"></a></p>
  
  <p><strong>Can anyone please help me how can I store the results also with its column names ??</strong></p>
  
  <blockquote>
    <p>My java Code is :</p>
  </blockquote>
  
  <pre><code>package com.automation;
  import org.apache.jmeter.engine.StandardJMeterEngine;  
  import org.apache.jmeter.reporters.ResultCollector;  
  import org.apache.jmeter.reporters.Summariser;  
  import org.apache.jmeter.save.SaveService;
  import org.apache.jmeter.testbeans.gui.TestBeanGUI;
  import org.apache.jmeter.testelement.TestElement;
  import org.apache.jmeter.util.JMeterUtils;  
  import org.apache.jorphan.collections.HashTree;  
  
  import java.io.File;  
  import java.io.FileInputStream;  
  
  public class JMeterFromExistingJMX {  
  
    public static void main(String[] argv) throws Exception {  
  
      //Set jmeter home for the jmeter utils to load  
      String jmeterHomelocation = "D:/apache-jmeter-5.1.1";  
      String jmeterPropertieslocation = jmeterHomelocation + "/bin/jmeter.properties";  
  
      // JMeter Engine  
      StandardJMeterEngine jmeter = new StandardJMeterEngine();  
  
  
      // Initialize Properties, logging, locale, etc.  
      JMeterUtils.loadJMeterProperties(new File(jmeterPropertieslocation).getPath());  
      JMeterUtils.setJMeterHome(new File(jmeterHomelocation).getPath());  
      // you can comment this line out to see extra log messages of i.e. DEBUG level  
      JMeterUtils.initLogging();  
      JMeterUtils.initLocale();  
  
      // Initialize JMeter SaveService  
      SaveService.loadProperties();  
  
     /* // Load existing .jmx Test Plan  
      FileInputStream in = new FileInputStream(new File(jmeterHomelocation + "extras/slt_autoMa_Test.jmx"));  
      HashTree testPlanTree = SaveService.loadTree(in);  
      in.close(); */ 
  
      HashTree testPlanTree = SaveService.loadTree(new File("D:/test-root/SLT/JmeterFiles/slt_auto_test_java_blaze_script.jmx"));
  
      Summariser summer = null;    
      String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary");  
  
      if (summariserName.length() &gt; 0) {  
        summer = new Summariser(summariserName);  
      }  
  
      String logFile = "D:/test-root/SLT/JmeterFiles/resultss.csv";
      ResultCollector logger = new ResultCollector(summer);  
      logger.setFilename(logFile);
      testPlanTree.add(testPlanTree.getArray()[0], logger);  
  
      // Run JMeter Test  
      jmeter.configure(testPlanTree);  
      jmeter.run();  
    }  
  }
  </code></pre>