java getBytes
public class Main {
public static void main(String[] args){
String Str1 = "1576059389832";
try{
System.out.println(Str1);
System.out.println("返回值:" + Arrays.toString(Str1.getBytes()) );
System.out.println("返回值:" + Arrays.toString(Str1.getBytes( "UTF-8" )) );
System.out.println("返回值:" + Arrays.toString(Str1.getBytes( "ISO-8859-1" ) )); }
catch ( UnsupportedEncodingException e){
System.out.println("不支持的字符集"); }
}
}
1576059389832
返回值:[49, 53, 55, 54, 48, 53, 57, 51, 56, 57, 56, 51, 50]
返回值:[49, 53, 55, 54, 48, 53, 57, 51, 56, 57, 56, 51, 50]
返回值:[49, 53, 55, 54, 48, 53, 57, 51, 56, 57, 56, 51, 50]
注意:getBytes() 默认是UTF-8,Str1.getBytes() 返回byte数组地址
用Arrays.toString()进行内容打印
python bytearray
a = '1576059389832'
b = bytearray(a, encoding='utf-8')
print(b)
print([x for x in bytearray('1576059389832','windows-1252')])
print([x for x in bytearray('1576059389832','utf_8')])
print([x for x in bytearray('1576059389832','gbk')])
print([x for x in bytearray('1576059389832','latin_1')])
bytearray(b'1576059389832')
bytearray(b'1576059389832')
[49, 53, 55, 54, 48, 53, 57, 51, 56, 57, 56, 51, 50]
[49, 53, 55, 54, 48, 53, 57, 51, 56, 57, 56, 51, 50]
[49, 53, 55, 54, 48, 53, 57, 51, 56, 57, 56, 51, 50]
[49, 53, 55, 54, 48, 53, 57, 51, 56, 57, 56, 51, 50]
注意:print([x for x in bytearray('1576059389832', 'utf_8')]) 进行byte数组内容的输出,
bytearray('1576059389832',encoding='utf-8') 返回bytearray(b'1576059389832’)