j2me蓝牙传送文件过程中write()方法参数的疑问

davidwjz23 2010-03-21 09:29:17

/** Send image data. */
private void sendImageData(byte[] imgData, StreamConnection conn) {
if (imgData == null) {
return;
}

OutputStream out = null;

try {
out = conn.openOutputStream();
out.write(imgData.length >> 8); ---------------->这一行中write()的参数做什么用的,为什么要>>8
out.write(imgData.length & 0xff);
out.write(imgData);
out.flush();
} catch (IOException e) {
System.err.println("Can't send image data: " + e);
}

// close output stream anyway
if (out != null) {
try {
out.close();
} catch (IOException e) {
} // ignore
}
}



疑问在代码中间表示出,提前感谢高手的回答
...全文
48 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
kf156 2010-03-22
  • 打赏
  • 举报
回复
out.write(imgData.length >> 8); ---------------->这一行中write()的参数做什么用的,为什么要>>8
out.write(imgData.length & 0xff);


这两行代码是将imgData.length的长度int值,转成两个byte值(一个int是四byte,即这里只取short长度),并写入
>>8 是右移八位,一个byte是八位
zhlwwj1314 2010-03-22
  • 打赏
  • 举报
回复
接收部分代码有么?

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧