java.io.StreamCorruptedException - Android

时间:2014-10-08 18:33:05

标签: java android deserialization objectinputstream

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

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

但获得例外:

  

java.io.StreamCorruptedException

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

感谢。

1 个答案:

答案 0 :(得分:0)

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().