我需要检查我的代码是否对hdfs中的目录有写权限。所以我想用 hdfs.checkPermission(Path path) 但我只看到 setPermission(Path p, FsPermission permission) api中的方法。我该怎么做?当然,如果我没有写权限,我可以在目录中创建一个文件并捕获一个异常“permission denied”,但这不是我想要做的。
hdfs.checkPermission(Path path)
setPermission(Path p, FsPermission permission)
gmol16391#
getPermission 提供 FileStatus 对象
getPermission
FileStatus
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
1条答案
按热度按时间gmol16391#
getPermission
提供FileStatus
对象