问题
I am downloading files and saving them to SDCard and want to capture a event when SDCard is full. Right now it throws IOException if no memory is left on SDCard.
How to distinguish the memory full exception then the other IOExceptions?
Cheers, Prateek
回答1:
If you know how much data you are writing to the SD card, you could check whether there is sufficient space before you try to write and thus avoid the IOException altogether.
回答2:
If there is no such thing like NoMemoryLeftExeption then usually by the message.
You can check after the IOException space left on the SD Card... if more then some small amount then rethrow that exception else you can assume that this is MemoryFullException
回答3:
If the IOException message (e.getMessage()) contains the following text
ENOSPC (No space left on device)
you can be 100% sure the sd card is full.
来源:https://stackoverflow.com/questions/4540589/ioexception-is-thrown-when-sdcard-is-full