title: What should be the buffer size for transfering files over socket in java
body: <p>It may be stupid questions but I want to know what should be the buffer size for
  file transfer</p>
  
  <p>Here is the code for sending the file</p>
  
  <pre><code>try {
          ServerSocket serverSocket = new ServerSocket(1234);
          Socket socket = serverSocket.accept();
          jTextArea1.append("Accepted connection : " + socket+"\n");
          byte [] bytearray = new byte [10485760];      //Buffer size 10Mb
          FileInputStream fin = new FileInputStream(GetFile);
          BufferedInputStream bin = new BufferedInputStream(fin);
          int read;
           OutputStream os = socket.getOutputStream();
          while((read=bin.read(bytearray))!=-1){
              jTextArea1.append("Sending Files...\n");//I have printed the read variable
              System.out.println("Read: "+read);
              os.write(bytearray,0,read);
              os.flush();
  
          }
          socket.close();
          serverSocket.close();
          System.out.println("File transfer complete\n");
      } catch (IOException ex) {
          Logger.getLogger(BufferedFileTransfar.class.getName()).log(Level.SEVERE, null, ex);
      }
  }           
  </code></pre>
  
  <p>Note:- Input File size is 143mb so as per may buffer size file should be divided in 15 parts and it gets divided </p>
  
  <p>Output:-</p>
  
  <pre><code>Read: 10485760
  Read: 10485760
  Read: 10485760
  Read: 10485760
  Read: 10485760
  Read: 10485760
  Read: 10485760
  Read: 10485760
  Read: 10485760
  Read: 10485760
  Read: 10485760
  Read: 10485760
  Read: 10485760
  Read: 10485760
  Read: 3603264
  File transfer complete
  </code></pre>
  
  <p>So for the same file if I use large buffer then the it will be ok na?</p>