我有两个以下问题:
所以我一直在发送方使用以下代码:
InputStream inputStream = new FileInputStream(mFile);
byte[] buffer = new byte[BUFFER_SIZE];
double content_length = inputStream.available();
double total = 0;
int n;
double progress = 0;
while ((n = inputStream.read(buffer)) != -1)
{
total = total + n;
progress = (total * (100 / content_length));
Log.v(TAG, "progress : " + progress);
BluetoothConnection.writeBytes(buffer);
}
在接收方:
@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();
break;
}
}
}