title: Apache spark - convert JavaRDD to csv file
body: <p>I am try to write my <code>org.apache.spark.api.java.JavaRDD&lt;Object&gt;</code> as pipe separated text to <code>.txt</code> file using Apache spark. For that I am using the spark provided <code>saveAsTextFile</code> method. But issue with this method is, it directly writes the object to file with no formatting and I could not able to give proper file name too.</p>
  
  <p>So which is the best way to format/convert my object into pipe separated string and write that to .txt file and also what is proper way to name file.</p>
  
  <p>This is dependencies in <code>build.gradle</code></p>
  
  <pre><code>dependencies {
  
  provided(
          [group: 'org.apache.spark', name: 'spark-core_2.10', version: '1.4.0'],
          [group: 'org.apache.spark', name: 'spark-sql_2.10', version: '1.4.0'],
          [group: 'com.datastax.spark', name: 'spark-cassandra-connector-java_2.10', version: '1.4.0']
  )
  
      compile([
  
              [group: 'com.databricks', name: 'spark-csv_2.10', version: '1.4.0'],
      ])
  
  
  }
  </code></pre>