Search code examples
javahadoophdfs

How to get absolute path from Path in HDFS


I'm pretty much new to HDFS and faced the following problem: org.apache.hadoop.fs.Path does not have a method something like getAbsolutePath which would return String.

The toString method is not documented properly so is it reliable to use it?


Solution

  • org.apache.hadoop.fs.Path should return the full path. Yeah the toString method has barely any documentation but it works like it should!

    Perhaps this could work too:

    Path p = fs.getFileStatus(new Path(".")).getPath(); 
    URI(p.toString()).getPath(); 
    

    Reference: http://lucene.472066.n3.nabble.com/Is-there-a-way-to-get-an-absolute-HDFS-path-td3820562.html