1. hadoop fs -dus 的源码:
public static void dus(String src,Configuration conf) throws IOException { Path srcPath = new Path(src); FileSystem srcFs = srcPath.getFileSystem(conf); FileStatus status[] = srcFs.globStatus(new Path(src)); if (status==null || status.length==0) { throw new FileNotFoundException("Cannot access " + src + ": No such file or directory."); } for(int i=0; i<status.length; i++) { long totalSize = srcFs.getContentSummary(status[i].getPath()).getLength(); String pathStr = status[i].getPath().toString(); System.out.println(("".equals(pathStr)?".":pathStr) + "\t" + totalSize); } }
2.
FileSystem fs = new Path(s).getFileSystem(conf); System.out.println(fs.getContentSummary(new Path(s)).getLength());