title: print csv file with header(column names) with empty dataset in spark java
body: <p>I've to print the dataset in .csv file but condition is </p>
  
  <p>1) <strong>if dataset is empty than I've to only print the header (which is column names with pipe delimiter) in csv file</strong> like</p>
  
  <p>ID|FIRSTNAME|LASTNAME|GRADE</p>
  
  <p>2) and if dataset is not empty than print header with data in csv file</p>
  
  <p><strong>need the solution for 1st point</strong></p>
  
  <p>2nd point is working with this code</p>
  
  <pre><code>dataset.toDF().coalesec(1).write().format("csv")
     .option("delimiter","|")
     .option("header","true")
     .option("nullValue",null)
     .mode(Savemode.Overwrite)
     .save("path");
  </code></pre>