aspose file tools*
The moose likes Beginning Java and the fly likes copying files over a network Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "copying files over a network" Watch "copying files over a network" New topic
Author

copying files over a network

J Mangual
Greenhorn

Joined: Nov 15, 2008
Posts: 16
how do i copy files over a network using a socket? I have something written but I hard-code the file size.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

J Mangual wrote:how do i copy files over a network using a socket? I have something written but I hard-code the file size.


Well, you will need to design a protocol between the two sides -- maybe the sender can send the filename and filesize, prior to sending the bytes of the file.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
J Mangual
Greenhorn

Joined: Nov 15, 2008
Posts: 16
Here is some sample code I found while searching. Is there a way to transfer files which does not depend on the file size?

The Server:

The Client:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: copying files over a network