日期:2014-05-20  浏览次数:20576 次

java中传输完文件以后,再传输数据就会出现问题么?
发送方:
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"也写入到文件之中,而不会将其处理为信息,如何解决这个问题呢

------解决方案--------------------
引用楼主 baibinghere 的帖子:
发送方:
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会把最后的"wor…