Path path = new Path("/user/hadoop/input/file.txt");
Path path = new Path("/user/hadoop/input"); FileSystem fs = FileSystem.get(new Configuration()); FileStatus[] status = fs.listStatus(path); for (FileStatus s : status) { System.out.println("File Name : " + s.getPath().getName()); System.out.println("Is Directory? " + s.isDirectory()); }
Path path1 = new Path("/user/hadoop/input"); Path path2 = new Path("../../file.txt"); Path fullPath = path1.resolve(path2); System.out.println("Full Path: " + fullPath.toString());This code resolves the relative path "../../file.txt" to the full path "/user/hadoop/file.txt" by starting at the "/user/hadoop/input" directory and navigating up two levels before accessing the file. Overall, Java org.apache.hadoop.fs Path is a useful interface for working with file paths in a Hadoop cluster. It provides a range of methods for creating, accessing, and manipulating file paths, making it an essential library for developers working with Hadoop.