java將固定長度的byte數組轉成String,並去掉後面多餘的0

String tostr(byte[] buffer) { try { int length = 0; for (int i = 0; i < buffer.length; ++i) { if (buffer[i] == 0) { length = i; break; } } return new String(buffer, 0, length, "UTF-8"); } catch (Exception e) { Log.error(e.toString()); return ""; } }
相關文章
相關標籤/搜索