[英]Converting byte array with ASCII encoding to String produces weird result
[英]Converting byte array containing ASCII characters to a String
我有一個字節數組,由我希望轉換為String的ASCII字符組成。 例如:
byte[] myByteArray = new byte[8];
for (int i=0; i<8; i++) {
byte[i] = (byte) ('0' + i);
}
循環后,myByteArray應包含字符串“12345678”。 如何將此字符串轉換為String變量?
謝謝!
String aString = new String(yourByteArray);
要么
String aString = new String(yourByteArray, "aCharSet");
//Replacing "aCharSet" with the appropriate chararacter set
輕松查看文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.