Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.net.Socket;
- import java.net.UnknownHostException;
- public class Client {
- private static final String IP = "127.0.0.1";
- private static final int PORT = 5000;
- private static final String FILE_NAME = "input.txt";
- private static final int BUFFER_SIZE = 1024;
- public static void main(String[] args) {
- try {
- Socket socket = new Socket(IP, PORT);
- BufferedOutputStream output = new BufferedOutputStream(
- socket.getOutputStream());
- File file = new File(FILE_NAME);
- FileInputStream input = new FileInputStream(file);
- byte[] buffer = new byte[BUFFER_SIZE];
- int bytesRead = -1;
- while ((bytesRead = input.read(buffer, 0, buffer.length)) != -1) {
- output.write(buffer, 0, bytesRead);
- }
- input.close();
- output.close();
- socket.close();
- } catch (UnknownHostException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement