FileSystem fs = FileSystem.get(new Configuration()); Path dirPath = new Path("/user/data"); FileStatus[] fileStatus = fs.listStatus(dirPath); for (FileStatus status : fileStatus) { System.out.println(status.getPath().getName()); System.out.println(status.getLen()); System.out.println(status.isDirectory()); }
FileSystem fs = FileSystem.get(new Configuration()); Path dirPath = new Path("/user/data"); FileStatus[] fileStatus = fs.listStatus(dirPath, new PathFilter() { @Override public boolean accept(Path path) { FileSystem fs = path.getFileSystem(new Configuration()); return fs.isFile(path); } }); for (FileStatus status : fileStatus) { System.out.println(status.getPath().getName()); }This code is similar to the previous example, but it includes a `PathFilter` as a second argument to `listStatus`. The filter determines whether each file is included in the resulting array based on whether it is a file or not (folders are excluded). Both of these examples use the `org.apache.hadoop.fs` package library.