发送方:
DataOutputStream out=new DataOutputStream(new BufferedOutputStream(client.getOutputStream()));当我用out传输完文件以后,再使用
out.writeUTF("world");
out.flush();接收方
DataInputStream in=new DataInputStream(new BufferedInputStream(server.getInputStream()));我也用同样的方法用in来接收文件,再使用String s = in.readUTF();
但这里s接收不到数据,而in会把最后的"world"也写入到文件之中,而不会将其处理为信息,如何解决这个问题呢
DataOutputStream out=new DataOutputStream(new BufferedOutputStream(client.getOutputStream()));当我用out传输完文件以后,再使用
out.writeUTF("world");
out.flush();接收方
DataInputStream in=new DataInputStream(new BufferedInputStream(server.getInputStream()));我也用同样的方法用in来接收文件,再使用String s = in.readUTF();
但这里s接收不到数据,而in会把最后的"world"也写入到文件之中,而不会将其处理为信息,如何解决这个问题呢
读取时:先读文件长度,再按长度读取文件内容,最后再用in.readUTF()读取writeUTF写的内容。