IOException is thrown when SDCard is full

点点圈 提交于 2019-12-07 19:37:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!