// Set permissions of a file in HDFS FileSystem fs = FileSystem.get(new Configuration()); Path filePath = new Path("/user/hadoop/test.txt"); FsPermission permission = new FsPermission("755"); fs.setPermission(filePath, permission);
// Set permissions of a directory in HDFS FileSystem fs = FileSystem.get(new Configuration()); Path dirPath = new Path("/user/hadoop/testDir"); FsPermission permission = new FsPermission("777"); fs.setPermission(dirPath, permission);This code sets the permissions of the testDir directory to rwxrwxrwx (777) in the /user/hadoop directory of the HDFS. Both examples use the org.apache.hadoop.fs.FileSystem package library to access and manipulate files and directories in the HDFS, and the setPermission method to set the file/directory permissions.