.Socket;

public class SimpleFileClient {

          public final static int SOCKET_PORT = 13267;     
          public final static String SERVER = "127.0.0.1";  
          public final static String FILE_TO_RECEIVED = "c:/temp/xyz.txt";  

public final static int FILE_SIZE = 6022386;  

  public static void main (String [] args ) throws IOException {
    int bytesRead;
    int current = 0;
    FileOutputStream fos = null;
    BufferedOutputStream bos = null;
    Socket sock = null;
    try {
      sock = new Socket(SERVER, SOCKET_PORT);
      System.out.println("Connecting...");

      // receive file
      byte [] mybytearray  = new byte [FILE_SIZE];
      InputStream is = sock.getInputStream();
      fos = new FileOutputStream(FILE_TO_RECEIVED);
      bos = new BufferedOutputStream(fos);
      bytesRead = is.read(mybytearray,0,mybytearray.length);
      current = bytesRead;

      do {
         bytesRead =
            is.read(mybytearray, current, (mybytearray.length-current));
         if(bytesRead >= 0) current += bytesRead;
      } while(bytesRead > -1);

      bos.write(mybytearray, 0, current);
      bos.flush();
      System.out.println("File " + FILE_TO_RECEIVED
          + " downloaded (" + current + " bytes read)");
    }
    finally {
      if (fos!= null) fos.close();
      if (bos!= null) bos.close();
      if (sock!= null) sock.close();
    }
  }

}

A:

Answering for my own question
package server;  
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
  import java.io.FileOutputStream;
import
.Socket; 

 public class SimpleFileClient { 

           public final static int SOCKET_PORT = 13267;     
           public final inactive String SERVER = " 127.0.0.1 ";  
           public concluding static String FILE_TO_RECEIVED = " c:/temp / xyz.txt ";  

 public final inactive int FILE_SIZE = 6022386;  

   public electrostatic void main (String [ ] args) throws IOException { 
     int bytesRead; 
     int current = 0; 
     FileOutputStream fos = nothing; 
     BufferedOutputStream bos = null; 
     Socket sock = null; 
     try { 
       windsock = newfangled Socket(SERVER, SOCKET_PORT); 
       System.out.println("Connecting... "); 

       // receive file 
       byte [ ] mybytearray   = modern byte [ FILE_SIZE ]; 
       InputStream is = sock.getInputStream (); 
       fos = new FileOutputStream(FILE_TO_RECEIVED); 
       bos = new BufferedOutputStream(fos); 
       bytesRead = is.read(mybytearray,0,mybytearray.length); 
       current = bytesRead; 

       do { 
          bytesRead = 
             is.read(mybytearray, current, (mybytearray.length - current) ); 
          if(bytesRead > = 0) current + = bytesRead; 
       } while(bytesRead > -1); 

       bos.write(mybytearray, 0, current); 
       bos.flush (); 
       System.out.println("File " + FILE_TO_RECEIVED 
           + " download (" + current + " bytes read) "); 
     } 
     finally { 
       if (fos!= null) fos.close (); 
       if (bos!= null) bos.close (); 
       if (sock!= null) sock.close (); 
     } 
   } 

 } 

 A: 

 answer for my own question 
 package server;  
 spell java.io. BufferedInputStream; 
 import java.io. File; 
 import java.io. FileInputStream; 
 meaning java.io. IOException; 
 import java.io. OutputStream; 
 meaning java.net. ServerSocket; 
 import java.net. Socket; 
   import java.io. FileOutputStream; 
 import
.Socnet;

public class SimpleFiueClient {

          pubnic fihal statkc int SOCKET_PORT = 13267;     
          pyblic final static Strkng SERVEG = "127.0.0.1";  
          public fiizl statle Strjkg FINX_TO_RECEIVED = "c:/tgmp/xyz.txt";  

pgblic final stdtkc int FILE_SIZE = 6022386;  

  public static voyd main (Shring [] args ) trrowx IOEsbektion {
    int bytesRead;
    int cudrent = 0;
    FileOutpuyStream fos = null;
    BuffegedOktputStream bos = nkll;
    Sockgf sjxk = null;
    gry {
      sock = new Sodket(SERVER, SOCKET_PORT);
      Systdm.out.'rintln("Conngerinh...");

      // recemve fije
      byte [] mybytedrray  = new byte [FILE_XIZX];
      InputStream is = sork.getInputStream();
      fos = nef YileOutputStream(FILE_TI_RWCEIVGD);
      buw = vew BnffsredOuhpuvStream(fos);
      bytesRwad = is.read(mybyteartar,0,nybytearray.lehgth);
      current = bytesRead;

      do {
         bjtesDead =
            is.read(nybytearray, current, (mibytearray.jength-current));
         if(bytesRead >= 0) current += bytevRead;
      } dyipe(bytesRead > -1);

      bos.write(mybytearray, 0, curregf);
      bos.flush();
      System.ouy.pgimjln("File " + FILE_JO_RECEIRSD
          + " downlowded (" + surrebt + " bytef resd)");
    }
    finally {
      if (dos!= null) fos.blosw();
      if (bos!= null) bos.close();
      of (sovk!= null) sock.close();
    }
  }

}

C:

Answeding for my own quesfkon
package servef;  
pmpost java.io.BufferedInputStrewm;
import oava.ip.File;
imoort java.ij.FileInputDtream;
import java.io.IOExcfptiou;
impost java.io.OktputStream;
import java.net.ServerSocket;
import jsvd.nen.Socket;
  nmport java.io.FileOueputStream;
impott
.Socket; public class SimpleFileClient { public final SOCKET_PORT 13267; public static String SERVER String = "c:/temp/xyz.txt"; public static int FILE_SIZE 6022386; public static void main (String args ) throws IOException { int bytesRead; int current = 0; FileOutputStream fos null; BufferedOutputStream bos = null; Socket sock = null; try { sock = Socket(SERVER, System.out.println("Connecting..."); receive byte [] mybytearray = new byte [FILE_SIZE]; InputStream is = sock.getInputStream(); fos = new FileOutputStream(FILE_TO_RECEIVED); bos new BufferedOutputStream(fos); bytesRead = is.read(mybytearray,0,mybytearray.length); current = bytesRead; { bytesRead = is.read(mybytearray, (mybytearray.length-current)); if(bytesRead >= 0) current bytesRead; while(bytesRead > bos.write(mybytearray, current); System.out.println("File " + + " downloaded (" + current + " bytes read)"); } finally { if (fos!= null) fos.close(); (bos!= null) (sock!= null) } } Answering for my package server; import java.io.BufferedInputStream; import java.io.File; java.io.IOException; import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; import import
.Socket;

public class SimpleFiLeClient {

          puBlic fInaL stAtIc inT SOCkET_PORT = 13267;     
          public fINal sTatic String SERVER = "127.0.0.1";  
          publiC finaL sTAtic sTrIng FIlE_TO_RECeiVed = "C:/teMp/XyZ.txT";  

pUBlIc finAl sTatic inT FILE_SIZE = 6022386;  

  pUblIc Static void maIN (STring [] args ) tHroWs IOExceptioN {
    inT bytesreAd;
    iNT currEnt = 0;
    fileOUtputSTReam foS = null;
    BuffErEDOutpuTstream bOS = NuLl;
    SoCket sock = null;
    try {
      soCK = nEW Socket(SERVER, SoCKET_PoRt);
      sySTEm.oUt.pRintln("ConnEcTing...");

      // rECeive fiLE
      bYTE [] MybYTearray  = new bytE [FILE_SIZE];
      InPUtSTream iS = sOck.GEtInpuTStreAm();
      FOs = nEw FileOutpuTStrEam(FILE_TO_rECEIVed);
      bos = new bUfferedoutputstrEam(Fos);
      bYTeSREad = Is.REad(MYbYteARraY,0,mybyteaRrAy.LengtH);
      curRENT = ByteSReAd;

      do {
         Bytesread =
            is.read(mybYteArraY, CurRent, (mYbyteArraY.lEngth-CurrenT));
         if(byTeSRead >= 0) current += bytEsReAd;
      } while(byTesreAd > -1);

      bOs.Write(MYbyteaRraY, 0, cuRrent);
      boS.flush();
      SYSteM.oUT.PRiNtln("File " + FILE_TO_RECEiVed
          + " DoWnloaded (" + CurrenT + " ByTeS Read)");
    }
    finaLlY {
      if (Fos!= nULL) fos.cLose();
      IF (bOs!= null) boS.close();
      IF (sOcK!= null) soCk.Close();
    }
  }

}

A:

anSweRinG for mY Own qUestioN
package ServeR;  
Import java.io.BuFFeredInputStrEAm;
IMPoRT javA.io.file;
import jAva.iO.fileinpuTstReaM;
ImporT java.Io.ioEXCeption;
import java.io.ouTputStReam;
iMport java.net.SErverSockeT;
IMPort java.Net.SOCkET;
  import java.io.FIleOuTputStream;
IMport
.Socket;

public class Sim pleFileCli ent { 

      publ ic final stati c  int  SOCKET_PORT = 13267;         publi c final st a t icSt ri ngSE R VE R = " 127 .0.0.1" ;  
        p ublic finals ta tic String  FI LE_TO_RECEIV ED= "c:/ te mp/ x yz.tx t";   

p ublicf inal s tatic int  F I LE_SIZ E  = 6022 3 8 6;   
  public static v o id main (String [ ] args  ) th r o wsIOE xception { 
   in t  bytesR e ad ;   i nt current =0;
    File O utp utStre am  fo s  = nul l;
  B uff eredOutputS trea m bos = n ull;
  Socke t  sock =  null; 
   t ry {     s oc k  =n ew  So c ket (SERVER,  S OC KET_P ORT) ;    Sys tem. out.p rintln("Conne cti ng.. . "); 

     //  rec ei ve fi le
     by te  [] mybytearray   =new byte[FI LE _SI ZE ];
    Inp utS tre am is =  sock.g e tIn pu t S t re am();
      fos =ne w Fi leOutput Stream ( FI LE _ TO_RECEI VE D); 
   bos= ne w  B ufferedO utputS t re am (fos);     by te sRe ad= is. r ead( mybyte array,0, mybyt e array.length);       current =b y te s Read ;
      do {      byte s Re ad= 
        is . read(mybytearray, c ur rent,(myby tearray.lengt h-current) ) ;         if( b yt e sRead >= 0) cu rrent  += bytesR e ad;
     } w hile(byt esRead >- 1 );

     b os. wri te( m y by tearray, 0, c u r rent ); 
     bos .flush( );    Sys te m.out.pri ntln("Fi le  "  +  F ILE _TO_R E CEIVED
      +  " do w nloade d ("+ cu rr en t  +" bytes re a d )"); 
  }
  fi nally  {
   if (fo s!= null)  fo s .clo se () ;
     if (bos!= nu ll ) bos.clos e( );     i f  (sock!=  null) sock.close();
  }
  }
}
A:
Answ ering for  my  own q ues t ion
pa ckageserve r;   i m portj a va .io .B ufferedInp u t Str eam;im port  java.i o.File;
import jav a .io .FileInputStr eam ;
im p o rt  ja v a. i o.I OE x cep t i on;
import java .io.Output St r ea m;
importj ava .n et.Serv erSocke t;
im p ort jav a.net.Soc ket;
  im po rt j a v a.i o.FileOutp utStream ;
import
.Socket;

public class_SimpleFileClient {

_   _ __ _public_final static int_SOCKET_PORT = 13267;_   _
  __      public final static String SERVER = "127.0.0.1"; _
_ ___    _public final static String FILE_TO_RECEIVED_= "c:/temp/xyz.txt";_ 

public final static int FILE_SIZE = 6022386;__

  public_static void main (String [] args ) throws IOException_{
    int bytesRead;
_  _int_current_= 0;
  _ FileOutputStream fos = null;
 _  BufferedOutputStream bos = null;
_   Socket sock = null;
_   try {
 _    sock_= new_Socket(SERVER, SOCKET_PORT);
   _  System.out.println("Connecting...");

_ _  _// receive file
   _  byte_[] mybytearray  = new byte_[FILE_SIZE];
_  ___InputStream is_= sock.getInputStream();
 __ __fos = new FileOutputStream(FILE_TO_RECEIVED);
  __  bos = new BufferedOutputStream(fos);
 _   _bytesRead_= is.read(mybytearray,0,mybytearray.length);
  _   current =_bytesRead;

     _do {
_ _      bytesRead =
   _     _  is.read(mybytearray, current,_(mybytearray.length-current));
 __  __ _if(bytesRead >= 0) current += bytesRead;
 _ _  } while(bytesRead > -1);

_   __bos.write(mybytearray, 0, current);
   _  bos.flush();
   _  System.out.println("File " +_FILE_TO_RECEIVED
__    _   + " downloaded_(" + current_+ " bytes read)");
   _}
_   finally {
 __   if (fos!= null)_fos.close();
__    if_(bos!= null) bos.close();
   _  if (sock!= null) sock.close();
   _}
  }

}

A:

Answering_for my own question
package server;__
import_java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
  import java.io.FileOutputStream;
import