【发布时间】:2015-08-16 07:45:47
【问题描述】:
我想做蓝牙socket通讯发送文件
我通过缓冲区从 FileInputStream 读取数据,并将其写入其他输出流。
但是这个程序连续读取相同的数据,而不是读取下一个内容。
这是我的来源
MSendArgWrapper wrapper = makeWrapper(sendArg, MSendArgWrapper.MODE_SWITCH_FILE);
try {
byte[] bytes = CUtility.serialize(wrapper);
outStream.write(bytes);
outStream.flush();
File file = new File(filePath);
FileInputStream fis = new FileInputStream(file);
byte buf[] = new byte[1024];
do {
int numread = fis.read(buf);
if (numread <= 0)
break;
if(LOG_I_ENABLE)
Log.i(TAG, "[CCommunicateThread] Sending File... [" + numread + "] => " + buf.toString());
outStream.write(buf, 0, numread);
} while (true);
outStream.flush();
} catch (IOException e) {
e.printStackTrace();
onDisconnected();
}
这是日志
08-16 08:07:21.002 20001-21388/com.example.park.psyche I/CBluetoothManager: [CCommunicateThread] 发送文件... [1024] => [B@42b0ab48 08-16 08:07:21.002 20001-21388/com.example.park.psyche I/CBluetoothManager: [CCommunicateThread] 发送文件... [1024] => [B@42b0ab48 08-16 08:07:21.002 20001-21388/com.example.park.psyche I/CBluetoothManager: [CCommunicateThread] 发送文件... [1024] => [B@42b0ab48 08-16 08:07:21.002 20001-21388/com.example.park.psyche I/CBluetoothManager: [CCommunicateThread] 发送文件... [1024] => [B@42b0ab48 08-16 08:07:21.002 20001-21388/com.example.park.psyche I/CBluetoothManager: [CCommunicateThread] 发送文件... [1024] => [B@42b0ab48 08-16 08:07:21.002 20001-21388/com.example.park.psyche I/CBluetoothManager: [CCommunicateThread] 发送文件... [1024] => [B@42b0ab48 08-16 08:07:21.002 20001-21388/com.example.park.psyche I/CBluetoothManager: [CCommunicateThread] 发送文件... [1024] => [B@42b0ab48
有什么问题?
【问题讨论】:
标签: android bluetooth file-transfer fileinputstream