Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1.  public class clientSend implements Runnable {
  2.    
  3.         public void run(){}
  4.        
  5.     private Socket fileSocket;
  6.    
  7.     public clientSend(String file) {    //String host, int port, String file
  8.         try {
  9.             fileSocket = new Socket("192.168.0.17", 9092);
  10.             sendFile(file);
  11.         } catch (Exception e) {
  12.             e.printStackTrace();
  13.         }      
  14.     }
  15.    
  16.     public void sendFile(String file) throws IOException {
  17.         DataOutputStream outFrom = new DataOutputStream(fileSocket.getOutputStream());
  18.         FileInputStream inputFrom = new FileInputStream(file);
  19.         byte[] buffer = new byte[4096];
  20.        
  21.         while (inputFrom.read(buffer) > 0) {
  22.             outFrom.write(buffer);
  23.         }
  24.        
  25.         inputFrom.close();
  26.         outFrom.close();   
  27.     }
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement