Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get file size

Tags:

hadoop

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?

like image 371
zohar Avatar asked Nov 17 '11 12:11

zohar


2 Answers

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

Here is a link to the relevant documentation of Hadoop 2.2.0

like image 183
Thomas Jungblut Avatar answered Oct 15 '22 20:10

Thomas Jungblut


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.

like image 37
xu Bruce Avatar answered Oct 15 '22 20:10

xu Bruce