title: split large file into small files and save in different paths using spark
body: <p>How to split a large file/RDD/DF into small files and save to different paths.</p>
  
  <p>ex: If there is a file that contains usernames(single column)in a text file and wants to split that into N files and write that N files into different directories.</p>
  
  <pre><code>val x=20
  val namesRDD=sc.textfile("readPath")
  val N = namesRDD.count/x
  </code></pre>
  
  <p>How to split the namesRDD into N files and write those to some "savepath/N/" - i.e first file is written to "savepath/1/", the second file is written to "savepath/2/" and so on.</p>