本文介绍了StreamCorruptedException无效的流标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我发送了一个字符串数组,最初是一个序列化的对象类到我的php服务器端,这样我就可以把它作为文本保存到我的mysql数据库中 String temp = new 字符串(facetemplate,Charset.forName( UTF-8)); 字符串 feat = new 字符串(facefeatures,Charset.forName( UTF-8)); 我将String转换回字节数组但是当我想将它转换回一个对象时它会给我 java.io.StreamCorruptedException:无效的流标题:3F3F0573 这就是我转换回对象的方式 / * * *将字节数组转换为对象 * @param byteobject * @return byte [] byte * @throws IOException * @throws ClassNotFoundException ** / public static 对象 DeSerialise( byte [] byteobject)抛出IOException,ClassNotFoundException { ByteArrayInputStream in = new ByteArrayInputStream(byteobject); ObjectInputStream = new ObjectInputStream( in ); return 是 .readObject(); } 序列化我的对象类 / * * *将对象序列化为文件 * * @param< T> * * @param obj * @throws FileNotFoundException * / public 静态< T> void SerializeObject(Context context,T obj) throws FileNotFoundException,IOException { File cache = new 文件(context.getCacheDir(),config.FILE_NAME); if (!cache.exists()) cache.createNewFile(); FileOutputStream fos = new FileOutputStream(cache); ObjectOutputStream out = new ObjectOutputStream(fos); out .writeObject(obj); out .close(); } 但是有关我如何上课的更多信息到字节请看下面的链接 http://stackoverflow.com/questions/28673243/object-to-byte-arrray-conversion-and-byte-array-to-string-conversion [ ^ ] 我不知道为什么,但我猜它是因为我在发送之前最初做的字符串转换。不是真正的专家,所以任何帮助将不胜感激。谢谢解决方案 我认为toString导致问题。在上面给出的链接中,您提到要将字节对象保存在mysql DB的文本列中。而不是存储BLOB类型列中的值,并且不将字节对象转换为tostring。 问候, Panduranga。 I sent a stringed byte array which was initially a serialized object class to my php server side so that i can save it into my mysql database as a TEXTString temp = new String(facetemplate, Charset.forName("UTF-8"));String feat = new String(facefeatures, Charset.forName("UTF-8"));I convert the String back to a byte array but when i wan to convert it back to an object it gives mejava.io.StreamCorruptedException: invalid stream header: 3F3F0573This is how i did my conversion back to an object /** * Converts byte array to object * @param byteobject * @return byte[] byte * @throws IOException * @throws ClassNotFoundException **/public static Object DeSerialise(byte[] byteobject) throws IOException, ClassNotFoundException{ ByteArrayInputStream in = new ByteArrayInputStream(byteobject); ObjectInputStream is = new ObjectInputStream(in); return is.readObject();}Serializing my object class/** * Serialises an object to a file * * @param <T> * * @param obj * @throws FileNotFoundException */ public static <T> void SerializeObject(Context context, T obj) throws FileNotFoundException, IOException { File cache = new File(context.getCacheDir(), config.FILE_NAME); if (!cache.exists()) cache.createNewFile(); FileOutputStream fos = new FileOutputStream(cache); ObjectOutputStream out = new ObjectOutputStream(fos); out.writeObject(obj); out.close(); }but for further information on how i turned my class to bytes please see the link belowhttp://stackoverflow.com/questions/28673243/object-to-byte-arrray-conversion-and-byte-array-to-string-conversion[^]am not sure why but i am guessing it is because of the string conversion i did initially before sending it. Not really an expert so any help would be greatly appreciated. Thanks 解决方案 I think the toString is causing the problem. And in the above given link you mentioned that you are saving the byte object in a text column of mysql DB. Instead of that store the value in BLOB type column and don't convert byte object to tostring.Regards,Panduranga. 这篇关于StreamCorruptedException无效的流标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-24 04:43