• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

File copy is not performing correctly

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22258
119
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see any problems in this reading code. Are you sure that the server provides the correct data?
 
Sumanth Prabhakar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The code attached in the previous post is on the server side. The code on the client side which puts file data on the socket stream is

fin = new BufferedInputStream(new FileInputStream(file));
out = new BufferedOutputStream(socket.getOutputStream());
int data = fin.read();
System.out.println("File uploading.");
while(data != -1)
{
out.write(data);
data = fin.read();
}
out.flush();

I didn't understand the your question. What data are you taking about? Can you please explain it.

Thanks,
Sumanth
 
Sumanth Prabhakar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sumanth Prabhakar wrote:Hi,

The code attached in the previous post is on the server side. The code on the client side which puts file data on the socket stream is

fin = new BufferedInputStream(new FileInputStream(file));
out = new BufferedOutputStream(socket.getOutputStream());
int data = fin.read();
System.out.println("File uploading.");
while(data != -1)
{
out.write(data);
data = fin.read();
}
out.flush();

I didn't understand the your question. What data are you talking about? Can you please explain it.

Hi all I need help in solving the above problem. Please help me out.

Thanks,
Sumanth

 
grapes are vegan food pellets. Eat this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic