13

I am running a hadoop job, I have FileSystem object and Path object and I want to know what is the file (Path) size.

any idea?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
zohar
  • 2,298
  • 13
  • 45
  • 75

2 Answers2

28
long length = FileSystem#getFileStatus(PATH)#getLen();

Here is a link to the relevant documentation of Hadoop 2.2.0

Thomas Jungblut
  • 20,854
  • 6
  • 68
  • 91
  • 5
    Not sure when it changed, but it's now `getFileStatus` instead of `getStatus`. – gak Jul 29 '13 at 06:27
2

another API is(written in Scala):

    private def getFileSizeByPath(arg : String): Long = {
      val path = new Path(arg)
      val hdfs = path.getFileSystem(new Configuration())
      val cSummary = hdfs.getContentSummary(path)
      val length = cSummary.getLength
      length
    }

Note that the return Long type is Byte in size.

xu Bruce
  • 71
  • 8