title: Send file from PC to Android via Socket
body: <p>I have two problems with sending files on the computer from android
  the first problem, use the following code to send</p>
  
  <pre class="lang-java prettyprint-override"><code>Socket sock;
  try {
      sock = new Socket("172.16.3.120", 1025); 
      System.out.println("Connecting...");
  
      // sendfile
      File myFile = new File (Environment.getExternalStorageDirectory().getPath() + "/UchTeh/uchteh.db"); 
      byte [] mybytearray  = new byte [(int)myFile.length()];
      FileInputStream fis = new FileInputStream(myFile);
      BufferedInputStream bis = new BufferedInputStream(fis);
      bis.read(mybytearray,0,mybytearray.length);
      OutputStream os = sock.getOutputStream();
      System.out.println("Sending...");
      os.write(mybytearray,0,mybytearray.length);
      os.flush();
  
      sock.close();
  } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
  </code></pre>
  
  <p>file on your computer accept delphi</p>
  
  <pre><code>procedure TServerRcvThread.ClientExecute;
  var
    SockStream : TWinSocketStream;
    FileInfo   : TFileInfo;
    FileStream : TFileStream;
    RcvBuf     : array[0..140] of Byte;
    nRead      : Integer;
    nToRead    : Integer;
    nTotal     : Integer;
  begin
    FStatus := 'Unknown error';
    SockStream := TWinSocketStream.Create( ClientSocket, 10000 );
    try
      if SockStream.WaitForData(10000) then begin
        nRead := SockStream.Read( FileInfo, SizeOf(FileInfo) );
        if (nRead = SizeOf(FileInfo)) then  begin
          nTotal := 0;
          FileStream := TFileStream.Create( FDir + '\' + FileInfo.FileName, fmCreate );
          try
            while(nTotal &lt; FileInfo.FileLength) do begin
              nToRead := (FileInfo.FileLength - nTotal);
              if (nToRead &gt; SizeOf(RcvBuf)) then
                nToRead := SizeOf(RcvBuf);
              nRead := SockStream.Read( RcvBuf, nToRead );
              if (nRead = 0) then Exit;
              nTotal := nTotal + nRead;
              FileStream.Write( RcvBuf, nRead );
            end;
          finally
            FileStream.Free;
          end;
          if (nTotal = FileInfo.FileLength) then
            FStatus := 'File ' + FileInfo.FileName + ' received ('
                     + IntToStr(nTotal) + ' bytes)'
          else
            FStatus := 'File ' + FileInfo.FileName + ' error ('
                    + IntToStr(nTotal) + ' bytes)';
        end
        else
          FStatus := 'File info header error';
      end
      else begin
        FStatus := 'Client delay error';
        ClientSocket.Close;
        Terminate;
      end;
    finally
      SockStream.Free;
      Synchronize( SetStatus );
    end;
  end;
  </code></pre>
  
  <p>file size to send and receive various
  please help me, I myself will not understand the problem in its</p>