1

Is there a way I can determine the size of an image (jpg) file in Android? I want to know the size of the image and if that's 0KB then delete it. Many thanks.

Paul R
  • 202,568
  • 34
  • 375
  • 539
Heidi
  • 91
  • 2
  • 13

1 Answers1

0

Use File.length()

Will return 0 if:

  • if the file exists but contained zero bytes.
  • if the file does not exist
  • if the file is some OS-specific special file.

Also be advised that a file with the size of 0KB will not necessarily return 0 when calling file.length if the file is less than 1KB (for example 27 bytes).

DTH
  • 1,105
  • 3
  • 16
  • 36