Q:

Empty txt file is saved in Apache Spark in scala

I have a dataframe as below (I posted a part of it) and I need to save it in txt file but, we ever I do it, it saves a lots of empty files and shows me the following message in the logfile.  I should mention that, I use Mac OS and IntelliJ IDEA.  Can you help me where is my mistake.  Thanks. 
+-----------+-------------+-----+----+---+--------------------+------------------+---+---+---+---+--------------------+--------------------+-------------------+-----------------+------+
|   time_stamp_0|sender_ip_1|receiver_ip_2|count|rank| xi|                  pi|                 r|ip5|ip4|ip3|ip2|            variance|             entropy|     pre_chi_square| total_chi_square|attack|
+---------------+-----------+-------------+-----+----+---+--------------------+------------------+---+---+---+---+--------------------+--------------------+-------------------+-----------------+------+
|09:06:41.053816|   10.0.0.5|     10.0.0.1|  297|   1| 20|0.003367003367003367|0.8855218855218855| 20| 13|  1|263|4.412538280964408E-5| 0.01917081528216397| 16.055555555555557|64.22222222222223|     1|
|09:06:41.565362|   10.0.0.5|     10.0.0.1|  297|   2| 20|0.006734006734006734|0.8855218855218855| 20| 13|  1|263|0.004182025143605029| 0.03367397278277949| 14.222222222222221|64.22222222222223|     1|
|09:06:41.570799|   10.0.0.5|     10.0.0.1|  297|   3| 20|0.010101010101010102|0.8855218855218855| 20| 13|  1|263|0.015053931638407148|0.046415352021561516|               12.5|64.22222222222223|     1|
|09:06:42.093127|   10.0.0.5|     10.0.0.1|  297|   4| 20|0.013468013468013467|0.8855218855218855| 20| 13|  1|263|   0.032659844867216|0.058012630002462075|  10.88888888888889|64.22222222222223|     1|
|09:06:42.617228|   10.0.0.5|     10.0.0.1|  297|   5| 20|0.016835016835016835|0.8855218855218855| 20| 13|  1|263| 0.05699976483003157| 0.06875916206007743|   9.38888888888889|64.22222222222223|     1|
|09:06:43.141217|   10.0.0.5|     10.0.0.1|  297|   6| 20|0.020202020202020204|0.8855218855218855| 20| 13|  1|263| 0.08807369152685389| 0.07882773069847768|                8.0|64.22222222222223|     1|
|09:06:43.665672|   10.0.0.5|     10.0.0.1|  297|   7| 20| 0.02356902356902357|0.8855218855218855| 20| 13|  1|263| 0.12588162495768296| 0.08833250480886096|  6.722222222222222|64.22222222222223|     1|
|09:06:44.189268|   10.0.0.5|     10.0.0.1|  297|   8| 20|0.026936026936026935|0.8855218855218855| 20| 13|  1|263| 0.17042356512251874| 0.09735462887873032|  5.555555555555555|64.22222222222223|     1|
|09:06:44.192995| 

The picture of the out put is as below: (The success file and other files are empty)

The message in the log file: 
17/09/13 10:42:50 INFO ParquetWriteSupport: Initialized Parquet WriteSupport with Catalyst schema:
{
  "type" : "struct",
  "fields" : [ {
    "name" : "time_stamp_0",
    "type" : "string",
    "nullable" : true,
    "metadata" : { }
  }, {
    "name" : "sender_ip_1",
    "type" : "string",
    "nullable" : true,
    "metadata" : { }
  }, {
    "name" : "receiver_ip_2",
    "type" : "string",
    "nullable" : true,
    "metadata" : { }
  }, {
    "name" : "count",
    "type" : "long",
    "nullable" : false,
    "metadata" : { }
  }, {
    "name" : "rank",
    "type" : "integer",
    "nullable" : true,
    "metadata" : { }
  }, {
    "name" : "xi",
    "type" : "long",
    "nullable" : false,
    "metadata" : { }
  }, {
    "name" : "pi",
    "type" : "double",
    "nullable" : true,
    "metadata" : { }
  }, {
    "name" : "r",
    "type" : "double",
    "nullable" : false,
    "metadata" : { }
  }, {
    "name" : "ip5",
    "type" : "long",
    "nullable" : false,
    "metadata" : { }
  }, {
    "name" : "ip4",
    "type" : "long",
    "nullable" : false,
    "metadata" : { }
  }, {
    "name" : "ip3",
    "type" : "long",
    "nullable" : false,
    "metadata" : { }
  }, {
    "name" : "ip2",
    "type" : "long",
    "nullable" : false,
    "metadata" : { }
  }, {
    "name" : "variance",
    "type" : "double",
    "nullable" : true,
    "metadata" : { }
  }, {
    "name" : "entropy",
    "type" : "double",
    "nullable" : true,
    "metadata" : { }
  }, {
    "name" : "pre_chi_square",
    "type" : "double",
    "nullable" : true,
    "metadata" : { }
  }, {
    "name" : "total_chi_square",
    "type" : "double",
    "nullable" : false,
    "metadata" : { }
  }, {
    "name" : "attack",
    "type" : "integer",
    "nullable" : false,
    "metadata" : { }
  } ]
}
and corresponding Parquet message type:
message spark_schema {
  optional binary time_stamp_0 (UTF8);
  optional binary sender_ip_1 (UTF8);
  optional binary receiver_ip_2 (UTF8);
  required int64 count;
  optional int32 rank;
  required int64 xi;
  optional double pi;
  required double r;
  required int64 ip5;
  required int64 ip4;
  required int64 ip3;
  required int64 ip2;
  optional double variance;
  optional double entropy;
  optional double pre_chi_square;
  required double total_chi_square;
  required int32 attack;
}

Here is my code:
 final_dataframe.write.save("/Users/saeedtkh/Desktop/Testoutput")

A:

According to answer number one, again the output was save as a empty file but, number of files could decrease.  
I used the data-brick library.  It makes the output in CSV file.  As the file saved in CSV, I changed it into txt.  Thanks to the answer number one, I used the mentioned code to decrease the number of output.  Here is the code that I used:
     sqlContext.setConf("spark.sql.shuffle.partitions","1")
final_add_count_rank_xi_pi_r_attack.write.format("com.databricks.spark.csv").option("header",true).option("inferSchema", true).save("/Users/saeedtkh/Desktop/Testoutput")

