【发布时间】:2014-05-11 05:57:38
【问题描述】:
当我尝试读取存储在文件中的 cripted 对象时,显然一切正常 并且我可以获得保存的值,但在日志中总是出现此错误
java.io.StreamCorruptedException
W/System.err﹕ at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:2067)
W/System.err﹕ at java.io.ObjectInputStream.<init>(ObjectInputStream.java:372)
我不明白如何解决它
我用这个来加载:
ObjectInputStream inputStream = null;
try {
inputStream = new ObjectInputStream(cipherInputStream);
} catch (IOException e) {
e.printStackTrace();
}
if (inputStream != null) {
try {
myDecipheredObject = (Serializable) inputStream.readObject();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
这个要存储
ObjectOutputStream outputStream = null;
try {
outputStream = new ObjectOutputStream(cipherOutputStream);
outputStream.writeObject(object);
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (RuntimeException e) {
e.printStackTrace();
}
错误发生在这行加载方法中
inputStream = new ObjectInputStream(cipherInputStream);
【问题讨论】:
-
你能展示你用来创建密码输入和输出流的代码吗?
-
我在其他各种方法中使用了与此处使用的密码相同的代码,但此错误只发生在这里,所以我几乎可以肯定问题的原因是另一个。
标签: java android file-io fileinputstream fileoutputstream