Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 15th, 2009, 02:05 AM
Authorized User
 
Join Date: Jul 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default copy a file from the server to the client

hi i'm kind of new to java an i want to copy a file between a simple server and a simple client.

I know how to do the client and the server (using Socket class and ServerSocket), but i dont know how to copy a file. I know how to copy a file in my machine with Input Stream and FileInputStream, but i don't know how to use it over the net.

Server
Code:
import java.net.*;
public class server
{
 public static void main(String arg[]) throws IOException
 {
  int port = 8080;
  ServerSocket s = new ServerSocket(port);
 
  try
  {
   Socket socket = s.accept();
   //copy file  code here
 
   socket.close();   
  }
  finally
  {
   s.close();
  }
 }
}
Client

Code:
import java.net.*;
public class client
{
 public static void main(String arg[]) throws IOException
 {
  InetAddress addr = InetAddress.getByName(null);//because i'm in my pc
  Socket socket = new Socket(addr, server.port);
 
  try
  {
 
 
  }
  finally
  {
   socket.close();
  }
 }
}
If you can provide a simple example it will be very helpful

Thanks in advance for your help.

Last edited by diegoblin; April 15th, 2009 at 02:35 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy file from one server to another server rhd110 General .NET 1 September 30th, 2007 10:37 AM
how to send xml file from server to client samarjit_mishra XML 1 January 27th, 2007 09:22 AM
Uploading file from client to server with ASP yours_idless Classic ASP Basics 2 November 22nd, 2004 07:13 PM
Uploading file from client to server with ASP yours_idless Classic ASP Professional 4 November 18th, 2004 12:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.