Advertisement
vanillajelly

Untitled

Jun 27th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3. public class MultiTransferClientA {
  4. public static void main(String[] args) throws IOException {
  5. System.out.println("Connecting to server...\n");
  6. Socket socket = null;
  7. String host = "172.31.34.186";
  8. socket = new Socket(host, 1234);
  9. System.out.println("Uploading file...\n");
  10. File file = new File("A:\\kirimBkeA.png");
  11. // Get the size of the file
  12. long length = file.length();
  13. byte[] bytes = new byte[16 * 1024];
  14. InputStream in = new FileInputStream(file);
  15. OutputStream out = socket.getOutputStream();
  16.  
  17. int count;
  18. while ((count = in.read(bytes)) > 0) {
  19. out.write(bytes, 0, count);
  20. }
  21. System.out.println("Transfer complete. Closing connection...\n");
  22. out.close();
  23. in.close();
  24. socket.close();
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement