Android - Sending file over bluetooth <p>I'm developing an Android application sending files from one device to another. Establishing the connection between both devices works perfectly, but there is something going wrong while transferring the file. On the receiving device, the file gets created but unfortunately it's empty.</p> <p>This is my code for handling the incoming file:</p> <pre><code>try { byte[] buffer = new byte[1024]; int bytes = 0; boolean eof = false; File file = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), "test.jpg"); OutputStream os = null; try { os = new BufferedOutputStream(new FileOutputStream(file)); } catch (FileNotFoundException e) { e.printStackTrace(); } while (!eof) { bytes = mmInStream.read(buffer); int offset = bytes - 11; byte[] eofByte = new byte[11]; eofByte = Arrays.copyOfRange(buffer, offset, bytes); String message = new String(eofByte, 0, 11); if(message.equals("end of file")) { os.flush(); os.close(); eof = true; } else { os.write (buffer); } } } catch (IOException e) { e.printStackTrace(); } </code></pre>