2014-10-08 52 views
0

我正在開發一個應用程序,其中從服務器下載的文件被加密。在應用程序中,我試圖打開存儲在內部存儲,以解密加密文件:java.io.StreamCorruptedException - Android

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

但是,讓一個例外:

java.io.StreamCorruptedException

什麼這個錯誤是否意味着在這種情況下,以及如何解決它?

謝謝。

回答

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

相關問題