【问题标题】:java.io.StreamCorruptedException - Androidjava.io.StreamCorruptedException - Android
【发布时间】:2014-10-08 18:33:04
【问题描述】:

我正在开发一个应用程序,其中从服务器下载的文件是加密的。在应用程序中,我试图打开存储在内部存储中的加密文件以对其进行解密:

ObjectInputStream ois = new ObjectInputStream(new CipherInputStream(context.openFileInput("filename"), cipher));
String result = (String) ois.readObject();

但遇到异常:

java.io.StreamCorruptedException

在这种情况下这个错误意味着什么,以及如何解决它?

谢谢。

【问题讨论】:

    标签: java android deserialization objectinputstream


    【解决方案1】:

    From the documentation:

    Thrown when control information that was read from an object stream violates internal consistency checks.

    From this helpful google search:

    Essentially, what happens is that, somehow or other, the writing and the reading get "out of kilter". Here are a couple of ways it can happen:

    1. Forgetting to close the ObjectOutputStream that wrote the data (or closing the wrong stream)

    2. Forgetting to check the return value of InputStream.read().

    【讨论】:

      猜你喜欢
      • 2012-04-03
      • 2016-05-16
      • 1970-01-01
      • 1970-01-01
      • 2011-02-25
      • 2021-02-08
      • 1970-01-01
      • 2013-04-05
      相关资源
      最近更新 更多