Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- public class MultiTransferClientA {
- public static void main(String[] args) throws IOException {
- System.out.println("Connecting to server...\n");
- Socket socket = null;
- String host = "172.31.34.186";
- socket = new Socket(host, 1234);
- System.out.println("Uploading file...\n");
- File file = new File("A:\\kirimBkeA.png");
- // Get the size of the file
- long length = file.length();
- byte[] bytes = new byte[16 * 1024];
- InputStream in = new FileInputStream(file);
- OutputStream out = socket.getOutputStream();
- int count;
- while ((count = in.read(bytes)) > 0) {
- out.write(bytes, 0, count);
- }
- System.out.println("Transfer complete. Closing connection...\n");
- out.close();
- in.close();
- socket.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement