you can convert the dataframe to rdd and covert the row to string and write the last line as
val op= sourcefile.rdd.map(_.toString()).saveAsTextFile("C:/Users/phadpa01/Desktop/op")
Edited
As @philantrovert and @Pravinkumar have pointed that the above would append [
and ]
in the output file, which is true. The solution would be to replace
them with empty
character as
val op= sourcefile.rdd.map(_.toString().replace("[","").replace("]", "")).saveAsTextFile("C:/Users/phadpa01/Desktop/op")
One can even use regex
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…