java transfer file over socket

Solutions on MaxInterview for java transfer file over socket by the best coders in the world

showing results for - "java transfer file over socket"
Diego Alejandro
11 May 2017
1Socket socket =  new Socket() ; //Open a socket with the server
2OutputSteam opt = socket.getOutputStream ; // get the outputStream of the socket 
3// so we can write in it 
4File file = new File(" Path of the file you want to send ") ; 
5FileInputStream fis = new FileInputeStream(file) ; 
6
7byte[] data = new byte[ 1024 * 16 ] ;
8int count  ; 
9while( (count  = fis.read(data))  > 0){
10  opt.write(data , 0 , count) ; 
11}