6

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
  • 16,671
  • 18
  • 103
  • 164

5 Answers5

13

Unfortunately in windows you have to escape "\".

Try:

"C:\\spark-1.3.1-bin-hadoop2.4\\README.md"
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
ayan guha
  • 1,249
  • 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
  • 361
  • 3
  • 5
2

In windows you have to specify as follows:

"file///C:/spark-1.3.1-bin-hadoop2.4/README.md"
Sushil Ks
  • 403
  • 2
  • 10
  • 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
  • 489
  • 6
  • 7
0

In windows, we can specify as:

spark.read.format("json").load("file:///C:/workspace/sample_data.json")
newbie
  • 1,282
  • 3
  • 20
  • 43