Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf);
Path file = new Path("/path/to/file"); BlockLocation[] blockLocations = fs.getFileBlockLocations(file, 0, fileSize);
for (BlockLocation blockLocation : blockLocations) { String[] dataNodeNames = blockLocation.getNames(); System.out.println("Block locations: " + Arrays.toString(dataNodeNames)); }Overall, the getFileBlockLocations method is a useful tool for understanding how a file is stored in a Hadoop cluster, and can be used for tasks such as data locality optimization and performance tuning.