問題遇到的現象和發生背景
芯燁打印機中文亂碼
問題相關代碼,請勿粘貼截圖
byte[] data2 = DataForSendToPrinterTSC.text(0, 0, "3", 0, 0, 0, "盧本偉的小店");byte[] data = byteMerger(byteMerger(byteMerger(byteMerger(data0, data4), data1), data2), data3);list.add(data);public static byte[] text(int x, int y, String font, int rotation, int x_multiplication, int y_multiplication, String content) { String str = "TEXT " + x + "," + y + ",\"" + font + "\"," + rotation + "," + x_multiplication + "," + y_multiplication + ",\"" + content + "\"\r\n"; byte[] data = strTobytes(str); return data; } private static byte[] strTobytes(String str) { byte[] b = null; byte[] data = null; try { byte[] b = str.getBytes("utf-8"); if (charsetName == null | charsetName == "") { charsetName = "gbk"; } data = (new String(b, "utf-8")).getBytes(charsetName); } catch (UnsupportedEncodingException var4) { var4.printStackTrace(); } return data; }
運行結果及報錯內容
盧本偉的小店 亂碼
我的解答思路和嘗試過的方法
各種編碼都用過 gb2312 gbk utf-8 機器默認是gbk
我想要達到的結果
怎樣才不會亂碼