How to get file size

前端 未结 2 635
醉梦人生
醉梦人生 2021-01-17 11:42

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?

相关标签:
2条回答
  • 2021-01-17 11:44

    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.

    0 讨论(0)
  • 2021-01-17 11:45
    long length = FileSystem#getFileStatus(PATH)#getLen();
    

    Here is a link to the relevant documentation of Hadoop 2.2.0

    0 讨论(0)
提交回复
热议问题