I am trying to transfer an XML file in Java but the client which receives the file freezes in an infinite loop and I don't know how to solve it.
The code I am using to send the file is:
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();
and the code I am using to receive the file is:
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();
Could you help me?
Thank you!