How to write to HDFS using Scala

前端 未结 1 1096
攒了一身酷
攒了一身酷 2020-12-10 06:50

I am learning Scala and i need to write a custom file to HDFS. I have my own HDFS running on a Cloudera image using vmware fusion on my laptop.

This is my actual co

相关标签:
1条回答
  • 2020-12-10 07:29

    Have a look at this this example here. I think the problem is that you don't configure the default file system using

    conf.set("fs.defaultFS", "hdfs://quickstart.cloudera:8020")
    

    and pass the relative path, like so:

    fs.create(new Path("/tmp/mySample.txt"))
    

    to write to the file, call 'write' directly on the output stream returned by fs.create, like so:

    val os = fs.create(new Path("/tmp/mySample.txt"))
    os.write("This is a test".getBytes)
    
    0 讨论(0)
提交回复
热议问题