Use javs Socket to upload a compressed file and open the received File
Use javs Socket to upload a compressed file and open the received File
Public class TranFileServer {
Public static void main (String [] args ){
ServerSocket server;
Socket st;
Try {
Server = new serversockets (4000 );
St = server. accept ();
File receivedfile = new File ("src/2.rar ");
BufferedInputStream bin = new BufferedInputStream (st. getInputStream ());
FileOutputStream fout = new FileOutputStream (receivedfile );
Int I = bin. read ();
While (I! =-1 ){
Fout. write (I );
I = bin. read ();
}
} Catch (IOException e ){
E. printStackTrace ();
}
}
}
Client:
Public class TranFileClient {
Public static void main (String [] args ){
Try {
Socket st = new Socket ("localhost", 4000 );
File f = new File ("2.rar ");
FileInputStream fin = new FileInputStream (f );
BufferedOutputStream bout = new BufferedOutputStream (st. getOutputStream ());
Int size = fin. available ();
For (int I = 0; I <size; I ++ ){
Bout. write (fin. read ());
}
} Catch (IOException e ){
E. printStackTrace ();
}
}
}