title: File sending from multiple client to Single server in Java Socket Programming
body: <p>hi i am trying to create a program in java for sending files from multiple client to single server. is this is possible? </p>
  
  <p>i tried this could for multiple client and single server and also it is from server to client sending program.</p>
  
  <p>Client Program</p>
  
  <pre><code>public class Client {
  
      public Client(String ip,String path,int i) throws IOException {
  
          int filesize=2022386;
          int bytesRead;
          int currentTot = 0;
  
          File file=new File(path);
          File dir=new File("c:/PAMR/Dest"+i+"/");
          String name=file.getName();
  
          if(!dir.exists())
          {
              dir.mkdir();
          }
  
          Socket socket = new Socket(ip,9100);
          byte [] bytearray  = new byte [filesize];
          InputStream is = socket.getInputStream();
  
  
          FileOutputStream fos = new FileOutputStream(dir+"/"+name);
  
          BufferedOutputStream bos = new BufferedOutputStream(fos);
          bytesRead = is.read(bytearray,0,bytearray.length);
  
  
          currentTot = bytesRead;
  
          do {
              bytesRead =
                is.read(bytearray, currentTot, (bytearray.length-currentTot));
             if(bytesRead &gt;= 0) currentTot += bytesRead;
  
  
          } while(bytesRead &gt; -1);
  
  
          bos.write(bytearray, 0 , currentTot);
          bos.flush();
          bos.close();
          socket.close();
  
      }
  
  
  
  }
  </code></pre>
  
  <p>for Server</p>
  
  <pre><code>public class Source {
  
  
      public  Source(String path) throws IOException {
  
             ServerSocket serverSocket = new ServerSocket(9100);
             System.out.println("Server is in Listening Mode");
             Socket socket = serverSocket.accept();
  
             File transferFile = new File (path);
  
             byte [] bytearray  = new byte [(int)transferFile.length()];
             FileInputStream fin = new FileInputStream(transferFile);
             BufferedInputStream bin = new BufferedInputStream(fin);
  
             bin.read(bytearray,0,bytearray.length);
             OutputStream os = socket.getOutputStream();
  
  
  
             os.write(bytearray,0,bytearray.length);
             bin.close();
             os.close();
             os.flush();
             socket.close();
             serverSocket.close();
  
  
       }
  
  
  }
  </code></pre>
  
  <p>it is a part of code for my project i am doing.</p>
  
  <p>Any body pls help.</p>