posted 11 years ago
Hi,
I am uploading a file from client to server using sockets and below is the code for that.
BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(file));
int data = in.read();
while(data != -1)
{
fos.write(data);
data = in.read();
}
fos.flush();
Where in refers to socket inputstream. After this I am closing the in and fos stream in the finally block.
The problem is that at the server file is not getting copied completely. For eg if the file size is 5MB, only 4520KB is getting copied and remaining 80KB is lost. As a result I am not been able to open the files. This cannot be reproduced frequently, but it happens.
Does anybody know what is the reason behind this.
Thanks,
Sumanth