• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

File Transfer in Java Using Sockets

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
This is Ankur and i wanted to transfer an entire file(the size keeps varying) to a remote server which is listenning to a port for an imcoming file. Also, the file has to be transferred as a whole and not as streams.
Kindly, suggest a way to do the same.
Ankur
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankur
I don't think it would be possible to transfer the file "as a whole" and not using streams.
One or the otherway streams will be used because its after all "network" which does only understand stream of bits
Now, probably, you can read the whole file and put it in Byte array and then transfer that byte array as an ObjectOutputStream or something once you open a connection to the server and then get the output stream from the communication socket. By this I mean,
Socket s;
byte[] fileBytes;
ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
oos.write(fileBytes);
oos.close();
assuming you have proper Socket created and read the file in fileBytes array.
Btw, why you want to avoid streams?
Regards
Maulin
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Closing this dulpicate post; followupshere.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic