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.
Asked
Active
Viewed 116 times
1
-
@DTH I have gone though this link but it doesn't return the correct size. The size of my file is 0KB and this code in the link you provided returns 27. – Heidi Oct 20 '15 at 16:28
-
Wonder if this helps - http://stackoverflow.com/questions/9316986/how-to-get-the-size-of-an-image-in-android – deboshrestha Oct 20 '15 at 16:31
-
@DTH thanks a lot. You are right and it is working fine :) – Heidi Oct 20 '15 at 17:06
-
@DeboshresthaDe thanks for the link :) – Heidi Oct 20 '15 at 17:07
1 Answers
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