Hello,

Yes, path.toUri().getPath() is a reliable way to get the absolute path without 
scheme or authority as a String from a Path instance.  The Hadoop codebase 
itself uses this same pattern throughout a lot of JUnit tests when we need to 
run assertions on an absolute path.

--Chris Nauroth

From: Richards Peter <hbkricha...@gmail.com<mailto:hbkricha...@gmail.com>>
Date: Wednesday, December 9, 2015 at 1:12 AM
To: "user@hadoop.apache.org<mailto:user@hadoop.apache.org>" 
<user@hadoop.apache.org<mailto:user@hadoop.apache.org>>
Subject: Determine absolute path of a file in hdfs

Hi,

I have a situation where I need to determine the absolute path of a file in 
hadoop as a String. The path should exclude the schema and authority. Eg: 
/mn/op/data/t1.dat

I found the following option in hadoop api:
https://hadoop.apache.org/docs/r2.6.2/api/org/apache/hadoop/fs/Path.html#getPathWithoutSchemeAndAuthority%28org.apache.hadoop.fs.Path%29

The aforementioned api returns a Path object. I do not want a new Path object. 
Instead I would like to obtain the path as a String.

If I have the original path stored in a variable path (Path path), will 
path.toUri().getPath() be sufficient to retrieve the intended path as a String? 
I tried to obtain the path using this approach and I found it to work fine for 
the cases that I tested. But I would like to take a confirmation before I 
incorporate the code to my project.

Could you please confirm whether my approach is fine?

Thanks,
Richards Peter.

Reply via email to