当SD卡满则抛出IOException抛出、SD、卡满则、IOException

2023-09-06 05:54:59 作者:试卷,一张微凉的遗书

我下载文件并将其保存到SD卡,并希望捕获事件时,SD卡已满。现在它抛出IOException异常,如果没有记忆留在SD卡。

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.

如何区分内存已满例外,那么其他的IOExceptions?

How to distinguish the memory full exception then the other IOExceptions?

干杯,Prateek

Cheers, Prateek

推荐答案

如果你知道你有多少数据写入到SD卡上,你可以检查是否有足够的空间,你试图完全写,从而避免IOException异常前

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.