java.io.StreamCorruptedException:发送图像时无效的流标题

时间:2017-05-05 13:41:00

标签: java sockets

在我的服务器中,我正在尝试拆分图像并将其发送给客户端(这里称为资源)。问题是当我读取对象时,我得到了StreamCorruptedException。

服务器端:

Socket resSocket = resourceQueue.get(k).getSocket();
DataOutputStream dos = new DataOutputStream(resSocket.getOutputStream());

FileInputStream fis = new FileInputStream(chunksList.get(i));
byte[] data = new byte[fis.available()];
fis.read(data);

ObjectOutputStream oos = new ObjectOutputStream(resSocket.getOutputStream());
oos.writeObject(data);
oos.close();

客户端

ObjectInputStream ois = new ObjectInputStream(sock.getInputStream()); // Here i get the error
byte[] buffer = (byte[]) ois.readObject(); 
String path = "c:/JGCF/temp."+"jpg";
System.out.println(path);
FileOutputStream fos = new FileOutputStream(path);
fos.write(buffer);

0 个答案:

没有答案