How to transfer large files via Bluetooth as bytes under Android?

I've therefore used the following code on the sender's side:

InputStream inputStream = new FileInputStream (mFile);
byte[] buffer = new byte[BUFFER_SIZE];
double content_length = inputStream.available ();
double total = 0;
int n;
double progression = 0;
while ((n = inputStream.read (buffer)) !! = -1)
{
total = total + n;
progress = (total * (100 / content_length));
Log.v (TAG, "progress:" + progress);
BluetoothConnection.writeBytes (buffer);
}

and on the receiver side:

@Override
public void run ()
{
mInsecureAcceptThread.cancel ();
mInsecureAcceptThread.interrupt ();
byte[] buffer = new byte[4096];
int bytes;

FileOutputStream mUpdateFileOutputStream = new FileOutputStream (mFilePath);
while (true)
{
try
{
bytes = mInputStream.read (buffer);
Log.v (TAG, "length:" + bytes);
mUpdateFileOutputStream.write (buffer);
} catch (exception e)
{
e.printStackTrace ();
Pause;
}
}
}

I have two problems:
1. How do I know if the data in the file is transferred?
2. When the transmission stops, which I can see in logcat, and check the file in the destination directory, the file will be 36 MB and corrupted, while the original zip file will not corrupt only 10 MB. The size of the buffer is 4096.