Android ObjectInputStream(openFileInput) 总是抛出 IOException

发布于 2025-01-06 18:28:12 字数 464 浏览 2 评论 0原文

我正在尝试从内部存储(文件)中读取数据,但是遇到了问题。

我使用 FileInputStream fis = context.openFileInput(filename) 获得文件的 FileInputStream。 调用成功,没有任何失败。接下来,我尝试使用以下行创建一个 ObjectInputStream 对象:ObjectInputStream ois = new ObjectInputStream(fis)

这每次都会抛出IOException!我做错了什么?

我尝试使用 fis 作为 FileInputStreamInputStream 对象。 我可以使用 ObjectOutputStream 写入文件。

I'm trying to read from internal storage (a file) however i'm having issues.

I get a FileInputStream for a file using FileInputStream fis = context.openFileInput(filename).
The call is successful, nothing fails. Next I try to create an ObjectInputStream object using the following line: ObjectInputStream ois = new ObjectInputStream(fis).

This throws an IOException EVERY time!! What am I doing wrong?

I've tried using fis as a FileInputStream and as an InputStream object.
I'm able to write to a file using ObjectOutputStream.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文