Bookmark Topic Watch Topic
  • New Topic

Please kindly help

 
Huang Qingyan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
    Bookmark Topic Watch Topic
  • New Topic