import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.conf.Configuration; ... Configuration configuration = new Configuration(); configuration.set("fs.defaultFS", "hdfs://localhost:9000"); FileSystem fileSystem = FileSystem.get(configuration); Path realPath = new Path(path); System.out.println(fileSystem.getFileStatus(realPath).getLen());