Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please kindly help

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic