我正在尝试在 Java 中传输 XML 文件,但接收文件的客户端冻结在无限循环中,我不知道如何解决它。
我用来发送文件的代码是:
FileInputStream fileInputStream = new FileInputStream(new File("file.xml"));
byte[] buffer = new byte[socket.getSendBufferSize()];
int bytesRead = 0;
while((bytesRead = fileInputStream.read(buffer)) > 0)
{
out.write(buffer, 0, bytesRead);
}
out.flush();
fileInputStream.close();
我用来接收文件的代码是:
byte[] mybytearray = new byte[1024];
File file = new File("file.xml");
FileOutputStream fileOutputStream= new FileOutputStream(file);
int bytesRead = 0;
while((bytesRead = in.read(mybytearray, 0, mybytearray.length)) > 0);
{
fileOutputStream.write(mybytearray, 0, bytesRead);
}
fileOutputStream.close();
你可以帮帮我吗?
谢谢!