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
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 InputStreamOutputStream 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
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