5

I am using Spark on Windows. I know in *nix, accessing local file code likes this:

val textFile = sc.textFile("file:///usr/local/spark/README.md") 

But how can I access a local file on Windows? I have tried following methods:

val logFile = "C:\spark-1.3.1-bin-hadoop2.4\README.md"
val logFile = "file\\C:\spark-1.3.1-bin-hadoop2.4\README.md"

But all can't work.

Nan Xiao
  • 15,571
  • 16
  • 87
  • 149

4 Answers4

13

Unfortunately in windows you have to escape "\".

Try:

"C:\\spark-1.3.1-bin-hadoop2.4\\README.md"
OneCricketeer
  • 151,199
  • 17
  • 111
  • 216
ayan guha
  • 1,241
  • 10
  • 7
2

It should work with below code. Else try checking for spelling and correct path.

val path = "C:\\spark_home\\spark-2.2.0-bin-hadoop2.7\\README.md"
val read = sc.textFile(path)
Arun Goudar
  • 331
  • 2
  • 5
2

In windows you have to specify as follows:

"file///C:/spark-1.3.1-bin-hadoop2.4/README.md"
Sushil Ks
  • 393
  • 1
  • 7
  • 18
1

For CSV and txt file dont specify the format,

val file = "C:\\Users\\testUser\\IdeaProjects\\SparkDataQualityReporting\\SampleData"
val fileRDD = sparkSession.sparkContext.textFile(file)
Jacob Joy
  • 415
  • 6
  • 7