Write single CSV file using spark-csv

前端 未结 13 2089
心在旅途
心在旅途 2020-11-22 08:43

I am using https://github.com/databricks/spark-csv , I am trying to write a single CSV, but not able to, it is making a folder.

Need a Scala function which will take

13条回答
  •  梦如初夏
    2020-11-22 09:10

    There is one more way to use Java

    import java.io._
    
    def printToFile(f: java.io.File)(op: java.io.PrintWriter => Unit) 
      {
         val p = new java.io.PrintWriter(f);  
         try { op(p) } 
         finally { p.close() }
      } 
    
    printToFile(new File("C:/TEMP/df.csv")) { p => df.collect().foreach(p.println)}
    

提交回复
热议问题