aspose file tools*
The moose likes Servlets and the fly likes Please kindly help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

Please kindly help

Huang Qingyan
Greenhorn

Joined: Jan 18, 2002
Posts: 23
Dear developers,
Can you please kindly advise me on how to send a whole
file across the network.
For example, I create a socket between a server and
client. I wanted to send a abc.exe file from server to
client. I have try using BufferedReader's readLine()
method to read the abc.exe file line by line and send
them line by line. It has no problem sending and
receiving but when I open the file at the other side,
the file seems to be corrupt.
My another question is how to write java codes to
block certain port from coming into my PC or network.
I think the concept is something like a Firewall. Can
you please tell me the Java APIs for this issue?
Warmest Regards,
Franco
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12785
    
    5
The file is corrupted because BufferedReader attempts to interpret all data as unicode characters. Also readLine tries to find line end codes and discards them. In order to deal with binary data you must use IO classes in the InputStream OutputStream family. Use the methods that deal with byte arrays.
Blocking specific ports is a not something you can do with Java, you really do need a firewall.
Bill
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Huang -
PLease do not post the same topic in multiple forums. We provide these forums so that readers and posters can expect questions, answers and other information that are specific to the forum itself.
I have closed this thread in favor of the one in I/O. Because there is an aswer here already, I won't delete this one.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please kindly help