This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • Post Reply 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Transfering Files

 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Can anyone tell how can i transfer file from 1 computer to another through java Code?
My problem is that client will provide me with a file path at his computer and i want to bring that file on my computer. How can i do that.
Please provide any code snipt or suggest any good Tutorial.Please reply soon. I'll be gratefull.
Thanks
[ April 08, 2004: Message edited by: Ali Gohar ]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't post the same question in multiple forums
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ali,
The following code works for me:
public void sendFile(File file, Socket socket) throws Exception {
FileInputStream fis = new FileInputStream(file);
DataOutputStream dos = new
DataOutputStream(socket.getOutputStream());
DataInputStream dis = new DataInputStream(fis);
int b = dis.read();
while (b != -1) {
dos.write(b);
b = dis.read();
}
dos.flush();
}
public void recvFile(File file, Socket socket) throws Exception {
FileOutputStream fos = new FileOutputStream(file);
DataOutputStream dos = new DataOutputStream(fos);
DataInputStream dis = new DataInputStream(socket.getInputStream());
int b = dis.read();
while (b != -1) {
dos.write(b);
b = dis.read();
}
dos.flush();
dos.close();
}
Cheers
Stanley George
[ April 09, 2004: Message edited by: Stanley George ]
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another way is to use DATAGRAM Packet (UDP) protocol, but this method may stops the transmitting. But it is official accepted. look at java.sun.com a search for socket tutorials
 
A magnificient life is loaded with tough challenges. En garde tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic