Java – HDFS Java API checks permissions

HDFS Java API checks permissions… here is a solution to the problem.

HDFS Java API checks permissions

I need to check if my code has write access to directories in hdfs. So I want to use a method like hdfs.checkPermission(Path path), but I only see the setPermission(Path p, FsPermission permission) method in the API. What should I do?
Of course, if I don’t have write permission, I can create a file in the directory and catch the exception “permission denied”, but that’s not what I want to do.


getPermission is available for FileStatus objects

val hdfs = org.apache.hadoop.fs.FileSystem.get(new org.apache.hadoop.conf.Configuration() )

val permissions = hdfs.getFileStatus(new Path("/user/cloudera/text.txt")).getPermission

org.apache.hadoop.fs.permission.FsPermission = rwxrwxrwx

Related Problems and Solutions