title: load a local file to spark using sc.textFile()
body: <h1>Question</h1>
  
  <p>How to load a file from the local file system to Spark using sc.textFile? Do I need to change any -env variables? Also when I tried the same on my windows where  Hadoop is not installed I got the same error.</p>
  
  <h1>Code</h1>
  
  <pre><code>&gt; val inputFile = sc.textFile("file///C:/Users/swaapnika/Desktop/to do list")
  /17 22:28:18 INFO MemoryStore: ensureFreeSpace(63280) called with curMem=0, maxMem=278019440
  /17 22:28:18 INFO MemoryStore: Block broadcast_0 stored as values in memory (estimated size 61.8 KB, free 265.1 MB)
  /17 22:28:18 INFO MemoryStore: ensureFreeSpace(19750) called with curMem=63280, maxMem=278019440
  /17 22:28:18 INFO MemoryStore: Block broadcast_0_piece0 stored as bytes in memory (estimated size 19.3 KB, free 265.1 MB)
  /17 22:28:18 INFO BlockManagerInfo: Added broadcast_0_piece0 in memory on localhost:53659 (size: 19.3 KB, free: 265.1 MB)
  /17 22:28:18 INFO SparkContext: Created broadcast 0 from textFile at &lt;console&gt;:21
  File: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[1] at textFile at &lt;console&gt;:21
  
  &gt; val words = input.flatMap(line =&gt; line.split(" "))
  ole&gt;:19: error: not found: value input
    val words = input.flatMap(line =&gt; line.split(" "))
                ^
  
  &gt; val words = inputFile.flatMap(line =&gt; line.split(" "))
  : org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[2] at flatMap at &lt;console&gt;:23
  
  &gt; val counts = words.map(word =&gt; (word, 1)).reduceByKey{case (x, y) =&gt; x + y}
  </code></pre>
  
  <h1>Error</h1>
  
  <pre><code>apache.hadoop.mapred.InvalidInputException: Input path does not exist: file:/c:/spark-1.4.1-bin-hadoop2.6/bin/file/C:/Users/swaapnika/Desktop/to do list
     at org.apache.hadoop.mapred.FileInputFormat.singleThreadedListStatus(FileInputFormat.java:285)
     at org.apache.hadoop.mapred.FileInputFormat.listStatus(FileInputFormat.java:228)
     at org.apache.hadoop.mapred.FileInputFormat.getSplits(FileInputFormat.java:313)
     at org.apache.spark.rdd.HadoopRDD.getPartitions(HadoopRDD.scala:207)
     at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:219)
     at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:217)
     at scala.Option.getOrElse(Option.scala:120)
     at org.apache.spark.rdd.RDD.partitions(RDD.scala:217)
     at org.apache.spark.rdd.MapPartitionsRDD.getPartitions(MapPartitionsRDD.scala:32)
     at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:219)
     at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:217)
     at scala.Option.getOrElse(Option.scala:120)
     at org.apache.spark.rdd.RDD.partitions(RDD.scala:217)
     at org.apache.spark.rdd.MapPartitionsRDD.getPartitions(MapPartitionsRDD.scala:32)
     at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:219)
     at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:217)
     at scala.Option.getOrElse(Option.scala:120)
     at org.apache.spark.rdd.RDD.partitions(RDD.scala:217)
     at org.apache.spark.rdd.MapPartitionsRDD.getPartitions(MapPartitionsRDD.scala:32)
     at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:219)
     at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:217)
     at scala.Option.getOrElse(Option.scala:120)
     at org.apache.spark.rdd.RDD.partitions(RDD.scala:217)
     at org.apache.spark.Partitioner$.defaultPartitioner(Partitioner.scala:65)
     at org.apache.spark.rdd.PairRDDFunctions$$anonfun$reduceByKey$3.apply(PairRDDFunctions.scala:290)
     at org.apache.spark.rdd.PairRDDFunctions$$anonfun$reduceByKey$3.apply(PairRDDFunctions.scala:290)
     at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:147)
     at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:108)
     at org.apache.spark.rdd.RDD.withScope(RDD.scala:286)
     at org.apache.spark.rdd.PairRDDFunctions.reduceByKey(PairRDDFunctions.scala:289)
     at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:25)
     at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:30)
     at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:32)
     at $iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:34)
     at $iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:36)
     at $iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:38)
     at $iwC$$iwC.&lt;init&gt;(&lt;console&gt;:40)
     at $iwC.&lt;init&gt;(&lt;console&gt;:42)
     at &lt;init&gt;(&lt;console&gt;:44)
     at .&lt;init&gt;(&lt;console&gt;:48)
     at .&lt;clinit&gt;(&lt;console&gt;)
     at .&lt;init&gt;(&lt;console&gt;:7)
     at .&lt;clinit&gt;(&lt;console&gt;)
     at $print(&lt;console&gt;)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke(Method.java:497)
     at org.apache.spark.repl.SparkIMain$ReadEvalPrint.call(SparkIMain.scala:1065)
     at org.apache.spark.repl.SparkIMain$Request.loadAndRun(SparkIMain.scala:1338)
     at org.apache.spark.repl.SparkIMain.loadAndRunReq$1(SparkIMain.scala:840)
     at org.apache.spark.repl.SparkIMain.interpret(SparkIMain.scala:871)
     at org.apache.spark.repl.SparkIMain.interpret(SparkIMain.scala:819)
     at org.apache.spark.repl.SparkILoop.reallyInterpret$1(SparkILoop.scala:857)
     at org.apache.spark.repl.SparkILoop.interpretStartingWith(SparkILoop.scala:902)
     at org.apache.spark.repl.SparkILoop.command(SparkILoop.scala:814)
     at org.apache.spark.repl.SparkILoop.processLine$1(SparkILoop.scala:657)
     at org.apache.spark.repl.SparkILoop.innerLoop$1(SparkILoop.scala:665)
     at org.apache.spark.repl.SparkILoop.org$apache$spark$repl$SparkILoop$$loop(SparkILoop.scala:670)
     at org.apache.spark.repl.SparkILoop$$anonfun$org$apache$spark$repl$SparkILoop$$process$1.apply$mcZ$sp(SparkILoop.scala:997)
     at org.apache.spark.repl.SparkILoop$$anonfun$org$apache$spark$repl$SparkILoop$$process$1.apply(SparkILoop.scala:945)
     at org.apache.spark.repl.SparkILoop$$anonfun$org$apache$spark$repl$SparkILoop$$process$1.apply(SparkILoop.scala:945)
     at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
     at org.apache.spark.repl.SparkILoop.org$apache$spark$repl$SparkILoop$$process(SparkILoop.scala:945)
     at org.apache.spark.repl.SparkILoop.process(SparkILoop.scala:1059)
     at org.apache.spark.repl.Main$.main(Main.scala:31)
     at org.apache.spark.repl.Main.main(Main.scala)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke(Method.java:497)
     at 
  
  org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:665)
     at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:170)
     at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:193)
     at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:112)
     at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
  
  
  &gt;
  </code></pre>