0

I have tried by giving path as" hdfs://localhost:9000/path to file" but still its not working is there any other way to read file? I want to give the file path in program,but not as an argument on terminal...

Christian St.
  • 1,751
  • 2
  • 22
  • 41
  • 2
    Could you please provide a little more information? How are you trying to read? What error are you getting? Please improve the question a little to let others know what is actually happening. – joragupra Mar 21 '14 at 08:43
  • My Wordcount program output is in a file named psap.txt which is on hdfs and its path is user/hduser/ppp and i want to read that file..... – user3445538 Mar 21 '14 at 08:48
  • 1
    **How** do you want to read that file? Any code would be helpful – Christian St. Mar 21 '14 at 09:01
  • THis might help: http://www.bigdataspeak.com/2013/05/how-to-read-file-in-hdfs-using-hadoop_14.html – Amar Mar 21 '14 at 11:36

2 Answers2

0

If you have WebHDFS enabled (dfs.webhdfs.enabled set to true in hdfs-site.xml) then you can access the file with a simple REST call. Many client libraries can open HTTP URI's directly.

For Java, follow the example in Open stream from uri and construct the URI for your file using the examples in the WebHDFS REST API documentation. For example, I was able to open a file from HDFS on my cluster using the following URI: "http://namenode:50070/webhdfs/v1/sampledata/sample.log?op=OPEN"

Community
  • 1
  • 1
RickH
  • 2,416
  • 16
  • 17
0

If what you want is how read the contents of that file using Java code, then have a look at my answer: Programatically reading contents of text file stored in HDFS using Java.

Community
  • 1
  • 1
Chiron
  • 20,081
  • 17
  • 81
  • 133