File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Send a whole file across Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Send a whole file across " Watch "Send a whole file across " New topic

Send a whole file across

Huang Qingyan

Joined: Jan 18, 2002
Posts: 23
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,
Val Pecaoco
Ranch Hand

Joined: Dec 05, 2001
Posts: 156
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

"Knowledge is power, but enthusiasm is the key." -- Lavern Barn
Huang Qingyan

Joined: Jan 18, 2002
Posts: 23
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("", 15000);
FileOutputStream fs = new FileOutputStream("test.exe");
PrintWriter pw = new PrintWriter(sock.getOutputStream);
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,
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
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..
I agree. Here's the link:
subject: Send a whole file across
It's not a secret anymore!