title: Spark error "Output directory file already exists
body: <p>I executed simple sample (spark, Windows7) and get unexpected error message <strong>FileAlreadyExistsException</strong>. I cannot find the folder or file on my computer.</p>
  
  <blockquote>
    <p>Exception in thread "main"
    org.apache.hadoop.mapred.FileAlreadyExistsException: Output directory
    file:/PluralsightData/ReadMeWordCountViaApp already exists
            at org.apache.hadoop.mapred.FileOutputFormat.checkOutputSpecs(FileOutputFormat.java:131)
            at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1.apply$mcV$sp(PairRDDFunctions.scala:1191)
            at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1.apply(PairRDDFunctions.scala:1168)
            at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1.apply(PairRDDFunctions.scala:1168)</p>
  </blockquote>
  
  <pre><code>package main
  
  import org.apache.spark.SparkContext
  import org.apache.spark.SparkConf
  import org.apache.spark.SparkContext._
  
  object WordCounter {
      def main(args: Array[String]) {
          val conf = new SparkConf().setAppName("Word Counter")
          val sc = new SparkContext(conf)
          //val textFile = sc.textFile("file:///Spark/README.md")
          val textFile = sc.textFile("file:///README.md")
          val tokenizedFileData = textFile.flatMap(line=&gt;line.split(" "))
          val countPrep = tokenizedFileData.map(word=&gt;(word, 1))
          val counts = countPrep.reduceByKey((accumValue, newValue)=&gt;accumValue + newValue)
          val sortedCounts = counts.sortBy(kvPair=&gt;kvPair._2, false)
          sortedCounts.saveAsTextFile("file:///PluralsightData/ReadMeWordCountViaApp")
      }
  }
  </code></pre>
  
  <p>Sources of the sample can be found <a href="https://github.com/constructor-igor/TechSugar/tree/master/ScalaSamples/WordCounterSample" rel="nofollow noreferrer">https://github.com/constructor-igor/TechSugar/tree/master/ScalaSamples/WordCounterSample</a></p>