• 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

Send a whole file across

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear experts,
May I know how to send a whole file across to the other host. Normally what we did was to send a text file line by line or byte by byte. In my case here, I wanted to send a whole .exe file across.
Can you please kindly advise me on this.
Warmest regards,
Franco
 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Huang,
I'm afraid you have to bear with that
It's because the transport language of computers and the Internet is in bits and bytes, and you can only read it bit by bit either serially or in parallel.
Maybe it's more of a question of speed and capacity. Of course, if you have a gigabit fiber optic connection, a 100-MB file will be transfered in a zippy, such that the time it took will barely be noticeable and it appears you have transfered the "whole" file in one swoop.
Ex Animo Java!
-- Val
 
Huang Qingyan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear expert,
What you mean is no matter what extension my file is, I can only use byte by byte or line by line. Here is an example:
-----------------------------------------------
Socket sock = new Socket("127.0.0.1", 15000);
FileOutputStream fs = new FileOutputStream("test.exe");
PrintWriter pw = new PrintWriter(sock.getOutputStream);
pw.println(fs);
pw.flush;
-----------------------------------------------
Can I do it inorder to send the whole file across? So the other side will receive the file line by line too.
Please kindly advise me.
Warmest regards,
Franco
 
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I am understanding your requirement properly Perhaps the better way of doing it is using ObjectInputStream and ObjectOutputStream as these can handle the searlized objects. This offer a facility of sending the file as an object.
For Reading

For Writing:-

Am I right? Perhaps JGurus can tell better...Any comment Please..
regards,
Arun
 
Beauty is in the eye of the tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic