我正在尝试将文件传输到远程蓝牙设备,如下所示
while (availableBytes > 0 ) {
bytesRead = inStream.read(tempData,0,tempData.length);
mmOutStream.write(tempData,0,bytesRead);
mmOutStream.flush();
availableBytes = inStream.available();
}/* End of availableBytes */
虽然大文件 (500 KB) 的写入正在进行中,但 12 到 15 分钟后我收到 IO 异常“IOException:连接超时”。当我发送小于 100 KB 的小文件时,我已成功传输。 文件传输正在进行时我没有关闭套接字。 Android 中是否存在蓝牙套接字只能在某个固定时间限制内激活的限制?
请发表你的看法
最佳答案
InputStream.available() 并不像您认为的那样:
Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.
正确的方法是写入直到您命中 bytesRead == -1,发出 EOF(文件结束)信号。
关于java - Android:Outputstream.write - 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5329220/