は私はバイト配列と連結しなければならない文字列を持っているので、私はこれを出力し、この文字列、バイト配列の連結
String msg = "msg to show";
byte[] msgByte = new byte[msg.length()];
try {
msgByte = msg.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
byte[] command = {2,5,1,5}
byte[] c = new byte[msgByte.length + command.length];
System.arraycopy(command, 0, c, 0, command.length);
System.arraycopy(msjByte, 0, c, command.length, msjByte.length);
for(Byte bt:c)
System.out.println(bt+"");
を試みた:
2 5 1 5 109 115 103 32 ...
が、私が探している結果がこの
2 5 1 5 MSGです...
それはBluetoothプリンタ用のコマンドとして使われています原因私は1つのアレイでそれを必要とします。
方法はありますか、ご提案はありますか?
ありがとうございます! :)
あなたは正しい結果を持っています。アスキー(109)= m。コマンドコードと文字列を混在させたかなり低レベルのインターフェースですか? –
私の誤りは、配列のASCIIコードで何かが見つからないと思ったのですが、プリンタのコマンドの例は次のようになります:byte [] ESC_Z2 = {0x1b、0x5a、0x00、0x51、0x05、0x14、0x00、 'm'、 'e'、 's'、 's'、 'a'、 'g'、 'e'};だから私は純粋なASCIIコードを送信しようとしたが、それは動作しませんでしたが、それはコマンドのパラメータのためです –