[英]InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag
I'm trying to write a file and then read it again. 我正在尝试写入文件,然后再次读取。
My write code: 我的写代码:
ObjectOutputStream oos = null;
FileOutputStream fout = null;
try
{
Object myObject;
fout = new FileOutputStream(new File("C:\\Foo","Bar.log"));
oos = new ObjectOutputStream(fout);
oos.writeObject(myObject);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
oos.close();
fout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
My reader: 我的读者:
FileInputStream input;
try {
input = new FileInputStream(new File("C:\\Foo\\Bar.log"));
MyFile parsedObject = MyFileFormat.MyFile.parseFrom(input);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
But I'm getting this exception on the parser: 但是我在解析器上遇到了这个异常:
com.google.protobuf.InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag.
at com.google.protobuf.InvalidProtocolBufferException.invalidEndTag(InvalidProtocolBufferException.java:94)
Can anyone help? 有人可以帮忙吗?
You use java's ObjectOutputStream
to serialize your object, but using some custom de-serialization with guava involved? 您使用Java的
ObjectOutputStream
序列化对象,但是对番石榴使用一些自定义反序列化吗? If you use ObjectOutputStream
to write stuff, you should use ObjectInputStream to read it. 如果使用
ObjectOutputStream
编写内容,则应使用ObjectInputStream读取内容。 Also, your example does not make any sense. 另外,您的示例没有任何意义。 You never initialize
myObject
variable in serialization snippet, this code will simply not compile. 您永远不会在序列化代码段中初始化
myObject
变量,此代码将无法编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.