SDCard满时抛出IOException

发布于 2024-10-09 04:21:13 字数 138 浏览 0 评论 0原文

我正在下载文件并将其保存到 SDCard,并希望在 SDCard 已满时捕获事件。现在,如果 SDCard 上没有剩余内存,它会抛出 IOException。

如何区分内存已满异常和其他 IOException?

干杯, 普拉泰克

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半枫 2024-10-16 04:21:13

如果没有像 NoMemoryLeftExeption 这样的东西,那么通常是通过消息。


您可以检查 SD 卡上剩余的 IOException 空间...如果多于少量,则重新抛出该异常,否则您可以假设这是 MemoryFullException

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

拔了角的鹿 2024-10-16 04:21:13

如果您知道要向 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.

内心荒芜 2024-10-16 04:21:13

如果 IOException 消息 (e.getMessage()) 包含以下文本

ENOSPC(设备上没有剩余空间)

您可以 100% 确定 SD 卡已满。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文