title: Sending a file from a device to a computer does not work (File gets broken)
body: <p>I'm currently using this code to sent a file from my pc to a other pc.</p>
  
  <p>The reciever:</p>
  
  <pre><code>    String filename = "";
      Socket socket;
      DataInputStream din;
      DataOutputStream dout;
      BufferedReader br;
      FileOutputStream fos;
  
      try{
          ServerSocket serverSocket = new ServerSocket(5000);
          while(true) {
              socket = serverSocket.accept();
  
              din = new DataInputStream(socket.getInputStream());
              dout = new DataOutputStream(socket.getOutputStream());
  
              filename = din.readUTF();
  
              String[] splitname = filename.split(Pattern.quote("/"));
              String realfile = splitname[splitname.length -1];
  
              long sz = Long.parseLong(din.readUTF());
  
              BufferedInputStream get = new BufferedInputStream(socket.getInputStream());
  
              //Speicherort (Config?)
              fos = new FileOutputStream(new File(System.getProperty("user.home") + "/Send/Empfangen/" + realfile),true);
  
  
              long u;
              byte bb[]= new byte [1024];
              long bytesRead;
              do
              {
                  bytesRead = din.read(bb, 0, bb.length);
                  fos.write(bb,0,bb.length);
  
              }while(!(bytesRead&lt;1024));
              fos.close();
              dout.close();
              socket.close();
          }
  
      }catch(Exception ex) {
          ex.printStackTrace();
  
      }
  </code></pre>
  
  <p>The sender:</p>
  
  <pre><code>    Socket soc;
      DataOutputStream dc;
      PrintWriter pw;
      String msg = "";
      try{
          msg = "test.png";
  
          soc = new Socket("IP", 5000);
  
          dc = new DataOutputStream(soc.getOutputStream());
  
          //Filename
          dc.writeUTF(msg);
          dc.flush();
  
          File fi = new File(msg);
  
          long size = (int) fi.length();
  
          //Size of file
          dc.writeUTF(Long.toString(size));
          dc.flush();
  
          byte[] bytes = new byte[1024];
          FileInputStream in = new FileInputStream(fi);
          OutputStream out = soc.getOutputStream();
  
          int count;
          while ((count = in.read(bytes)) &gt; 0) {
              out.write(bytes, 0, count);
          }
  
          out.close();
          in.close();
          soc.close();
  
      }catch(Exception ex){
          ex.printStackTrace();
      }
  </code></pre>
  
  <p>If I use it like this, I can send any file from my laptop to my desktop pc.
  But when I copy this code into my app and send a file from my device,
  it gets broken. PDFs are only have half of the text, images only a quarter of its look.</p>
  
  <p>For example a profile picture:
  <a href="https://i.stack.imgur.com/IeSXp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IeSXp.png" alt=""></a></p>
  
  <p>This is what it looks on my phone.
  After the I sended it to my computer it looked like this:
  <a href="https://i.stack.imgur.com/JlWIO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JlWIO.png" alt=""></a></p>
  
  <p>So its now totaly broken.</p>
  
  <p>Why does it work from pc to pc, but not from android to pc?
  Is there any way to get this working?</p>
  
  <p>Thanks for answers ;)</p>