SQLiteDiskIOException,错误代码 10:磁盘 I/O 错误

发布于 2024-11-28 23:54:06 字数 169 浏览 3 评论 0原文

我将 SQLite 数据库移至 SD 卡,但有时会抛出以下异常:

android.database.sqlite.SQLiteDiskIOException: error code 10: disk I/O error

有关如何防止这种情况发生的任何建议?

I moved an SQLite database to an SD card, but sometimes it will throw the following exception:

android.database.sqlite.SQLiteDiskIOException: error code 10: disk I/O error

Any suggestions on how I can prevent this from happening?

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

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

发布评论

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

评论(1

属性 2024-12-05 23:54:06

由于您使用的是外部存储,因此您的应用程序必须了解外部存储状态,您可以通过 Environment.getExternalStorageState() 获取该状态。

您只能在状态为 MOUNTED 时访问外部存储。

如果您在设备启动期间尝试打开文件(或 SQLite DB;它只是一个文件!),您肯定会遇到问题,因为外部存储未安装直到进入设备启动(显示主屏幕后)。

解决这个问题的方法是注册一个 IntentFilter 来通知外部存储状态的所有变化,并做出相应的行为。

阅读文档总是一个好主意!有关详细信息,请参阅 Android 文档: http://developer.android.com/reference /android/os/Environment.html

使用外部存储来实现此目的是值得怀疑的,因为您无法控制它何时变得不可用!例如,用户将设备插入计算机上的 USB,并选择“启用 USB 海量存储”选项,以便他们可以从计算机访问设备的外部存储。坏消息!您的应用程序将与外部存储断开连接,并且很可能没有机会进行任何清理 IO!

在这种情况下,您现在需要如何处理要放入数据库的所有数据(如果有的话)。

Since you are using External Storage, your application must be aware of the External Storage state, which you can get via Environment.getExternalStorageState().

You must only access External Storage when the state is MOUNTED.

If you are trying to open a file (or SQLite DB; it's just a file!) during device startup, you will definitely have problems, because External Storage is not mounted until well into device startup (after Home Screen is displayed).

The way out of this is to register an IntentFilter to be notified of all changes in External Storage state, and behave accordingly.

It's always a good idea to read the documentation! See the Android documentation for details: http://developer.android.com/reference/android/os/Environment.html

Using External Storage for this purpose is dubious, because you cannot control when it becomes unavailable! For example, the user plugs their device into USB on their computer, and selects the "Enable USB Mass Storage" option, so they can access their device's External Storage from their computer. Bad news! Your app will be disconnected from External Storage, and most-likely without the opportunity to do any clean-up IO!

With this state of affairs, you are now left with What To Do with all the data you would be putting into your database, if only it were available.

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