Home > Back-end >  The Java ObjectInputStream readUTF EOFException anomalies ()
The Java ObjectInputStream readUTF EOFException anomalies ()

Time:09-23

ByteArrayOutputStream bo=new ByteArrayOutputStream ();
The ObjectOutputStream oo=new ObjectOutputStream (bo);
Oo. WriteUTF (" aaa ");
Byte [] bytes=bo. ToByteArray ();

ByteArrayInputStream bi=new ByteArrayInputStream (bytes);
ObjectInputStream oi=new ObjectInputStream (bi);
String STR=(String) oi. ReadUTF ();
System.out.println(str);

Can appear more than writing EOFException is unusual, but I change writeUTF writeObject good, this is why, correct code is as follows:

ByteArrayOutputStream bo=new ByteArrayOutputStream ();
The ObjectOutputStream oo=new ObjectOutputStream (bo);
Oo. WriteObject (" aaa ");
Byte [] bytes=bo. ToByteArray ();

ByteArrayInputStream bi=new ByteArrayInputStream (bytes);
ObjectInputStream oi=new ObjectInputStream (bi);
String STR=(String) oi. ReadObject ();
System.out.println(str);

CodePudding user response:

The problem have solved it, brother
  • Related