Advertisement
rafikamal

Client

Aug 6th, 2014
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. import java.io.BufferedOutputStream;
  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.IOException;
  5. import java.net.Socket;
  6. import java.net.UnknownHostException;
  7.  
  8.  
  9. public class Client {
  10.    
  11.     private static final String IP = "127.0.0.1";
  12.     private static final int PORT = 5000;
  13.     private static final String FILE_NAME = "input.txt";
  14.     private static final int BUFFER_SIZE = 1024;
  15.    
  16.     public static void main(String[] args) {
  17.         try {
  18.             Socket socket = new Socket(IP, PORT);
  19.             BufferedOutputStream output = new BufferedOutputStream(
  20.                     socket.getOutputStream());
  21.            
  22.             File file = new File(FILE_NAME);
  23.             FileInputStream input = new FileInputStream(file);
  24.            
  25.             byte[] buffer = new byte[BUFFER_SIZE];
  26.             int bytesRead = -1;
  27.             while ((bytesRead = input.read(buffer, 0, buffer.length)) != -1) {
  28.                 output.write(buffer, 0, bytesRead);
  29.             }
  30.            
  31.             input.close();
  32.             output.close();
  33.             socket.close();
  34.         } catch (UnknownHostException e) {
  35.             e.printStackTrace();
  36.         } catch (IOException e) {
  37.             e.printStackTrace();
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement