This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Send a whole file across

 
Huang Qingyan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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
 
Val Pecaoco
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic