我有这个 -
char[] uploadCommand2 = {0x7d, 0x4d, 0x01, 0x00, 0x01, 0xcb};
所以我可以使用它 -
//writing to outputstream
for(int k=0; k < uploadCommand2.length; k++){
try {
new DataOutputStream(socket.getOutputStream()).writeByte(uploadCommand2[k]);
} catch (IOException e) {
e.printStackTrace();
}
}
但是现在我有了这个 -
String numberthYear = "0x" + decodeDecToHex(numberOfYears); //Evaluate to 0x0E
String dayYear1 = "0x" + dayYear.substring(0, 2); //Evaluate to 0x01
String dayYear2 = "0x" + dayYear.substring(2, 4); //Evaluate to 0x11
String hour = "0x" + decodeDecToHex(now.get(Calendar.HOUR_OF_DAY)); //Evaluate to 0x0D
String minute = "0x" + decodeDecToHex(now.get(Calendar.MINUTE)); //Evaluate to 0x04
String second = "0x" + decodeDecToHex(now.get(Calendar.SECOND)); //Evaluate to 0x08
String timeString = "0x7D, 0x54, 0x06,
"+ numberthYear+", "+dayYear1+","+dayYear2+",
"+hour+","+minute+", "+second+" 0x01, 0x10";
格式与uploadCommand2
的格式相同。
但是那么如何将字符串timeString
写入outputstream
通过套接字,因为writeByte只接受int?