File Transfer In Java (Resumable)
Hi
I wanna make an application to transfer file from one system to another, direcly, i mean peer to peer (no servers). How can i do that, what api should i use, what classes,
Any Ideas???/
Web Development
Hi
I wanna make an application to transfer file from one system to another, direcly, i mean peer to peer (no servers). How can i do that, what api should i use, what classes,
Any Ideas???/
by jay eckles
java.net.Socket would be a good place to start. You'll also need java.io.File and other java.io classes for reading/writing to a file. You might use java.io.BufferedInputStream, I'm not sure how you want to do things.
To make the transfer resumable, the only thing I can think of immediately is to count the number of bytes that you've written previously, tell the sending program that you've already received the first x bytes, and it will skip those and start sending at x+1 bytes. Then append whatever it sends you to the incomplete file.
I would start with one of the many freely available Java FTP servers and clients. They will have much of the functionality you need, and you can pick and choose what code to re-use. You can use such a program to learn how to open a file and send it over a network connection.
Good luck.
by basit_jafri
by zeshanzia
To transfer files between two systems there is a very easy trick, and a programming trick.
1. Programming Trick:- Use File class method "renameTo" note that if Source and Destination are same it will rename your file, otherwise it will move your file from source to destination. (I used word "Move" not "Copied")
2. As you might need to Move file in other systems, if you have local Intranet then MAP the Folder of destination At Source (Windows)
OR
3. Use this sort of path as destination "//172.0.0.0/SharedFolderName" where first one is destination IP
4. At the Next Line of renameTo function, check whehter source exist through "exists()" function. If it is it means that the file movement is terminated due to some network problem and you can do the task AGAIN.
Rate this answer, if it helps
by basit_jafri
by basit_jafri
This discussion is closed to new replies.
Sort by Trending