Java – How to get an absolute path from Path in HDFS

How to get an absolute path from Path in HDFS… here is a solution to the problem.

How to get an absolute path from Path in HDFS

I’m new to HDFS and ran into the following issue: org.apache.hadoop.fs.Path doesn’t have a getAbsolutePath method that returns a string.

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

Solution

org.apache.hadoop.fs.Path should return the full path. Yes, the toString method hardly has any documentation, but it works!

Maybe this will work too:

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

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

Related Problems and Solutions