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
  • 208,748
  • 37
  • 389
  • 560
Heidi
  • 111
  • 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,133
  • 3
  • 16
  • 36