-3

I am unable to get the size of the image. Below is my code.

    File root = android.os.Environment.getExternalStorageDirectory();
    File dirM = new File(root.getAbsolutePath()+"/Download/images.jpeg");
    Long length = dirM.length();
Tome
  • 3,234
  • 3
  • 33
  • 36
Zahra
  • 17
  • 4
  • 2
    Possible duplicate of [Get the file size in android sdk?](https://stackoverflow.com/questions/7131930/get-the-file-size-in-android-sdk) – Piotr Golinski Aug 16 '17 at 13:11
  • You have just created a file with `new File(root.getAbsolutePath()+"/Download/images.jpeg");`. At this point there is no information about this file – GuilhermeFGL Aug 16 '17 at 13:11
  • I have an images.jpeg in /storage/emulated/0/Download/images.jpeg ,but I don't get size of images.jpeg. – Zahra Aug 16 '17 at 13:15

1 Answers1

1

You are actually fetching the length, not the size of the particular file. Use the below example to achieve what you want.

long imgSize = yourImageFileName.getAbsoluteFile().getTotalSpace();
vss
  • 1,093
  • 1
  • 20
  • 33
  • What is yourImageFileName ?Is yourImageFileName the address of the image ? – Zahra Aug 16 '17 at 13:53
  • Thats the name of the image file(in code) you are trying to fetch details of. In your case I think its `dirM `. – vss Aug 17 '17 at 05:23