第3个试验,将字符流按照UTF8方式编码后,写入第3个测试文件hello.utf8.html,我们可以看到UTF8对英文没有影响,但对于其他文字使用了3字节编码方式,因此比GB2312编码方式的存储要大50%,
========Testing2:readinganddecodingfromfiles========
[test2-1]:readhello.orig.html:decodingwithsystemdefaultencoding
string=Helloworld世界你好length=20
char[0]=’H’byte=72u48short=72u48BASIC_LATIN
char[1]=’e’byte=101u65short=101u65BASIC_LATIN
char[2]=’l’byte=108u6Cshort=108u6CBASIC_LATIN
char[3]=’l’byte=108u6Cshort=108u6CBASIC_LATIN
char[4]=’o’byte=111u6Fshort=111u6FBASIC_LATINchar[5]=’’byte=32u20short=32u20BASIC_LATIN
char[6]=’w’byte=119u77short=119u77BASIC_LATIN
char[7]=’o’byte=111u6Fshort=111u6FBASIC_LATIN
char[8]=’r’byte=114u72short=114u72BASIC_LATIN
char[9]=’l’byte=108u6Cshort=108u6CBASIC_LATIN
char[10]=’d’byte=100u64short=100u64BASIC_LATIN
char[11]=’’byte=32u20short=32u20BASIC_LATIN
char[12]=’?byte=-54uFFFFFFCAshort=202uCALATIN_1_SUPPLEMENT
char[13]=’?byte=-64uFFFFFFC0short=192uC0LATIN_1_SUPPLEMENT
char[14]=’?byte=-67uFFFFFFBDshort=189uBDLATIN_1_SUPPLEMENT
char[15]=’?byte=-25uFFFFFFE7short=231uE7LATIN_1_SUPPLEMENT
char[16]=’?byte=-60uFFFFFFC4short=196uC4LATIN_1_SUPPLEMENT
char[17]=’?byte=-29uFFFFFFE3short=227uE3LATIN_1_SUPPLEMENT
char[18]=’?byte=-70uFFFFFFBAshort=186uBALATIN_1_SUPPLEMENT
char[19]=’?byte=-61uFFFFFFC3short=195uC3LATIN_1_SUPPLEMENT
按系统从中间存储hello.orig.html文件中读取相应文件,虽然是按字节方式(半个“字”)读取的,但由于能完整的还原,因此输出显示没有错误。其实PHP等应用很少出现字符集问题其实就是这个原因,全程都是按字节流方式处理,很好的还原了输入,但这样处理的同时也失去了对字符的控制
[test2-2]:readhello.gb2312.html:decodingasGB2312
string=Helloworld????length=16
char[0]=’H’byte=72u48short=72u48BASIC_LATIN
char[1]=’e’byte=101u65short=101u65BASIC_LATIN
char[2]=’l’byte=108u6Cshort=108u6CBASIC_LATIN
char[3]=’l’byte=108u6Cshort=108u6CBASIC_LATIN
char[4]=’o’byte=111u6Fshort=111u6FBASIC_LATIN
char[5]=’’byte=32u20short=32u20BASIC_LATIN
char[6]=’w’byte=119u77short=119u77BASIC_LATIN
char[7]=’o’byte=111u6Fshort=111u6FBASIC_LATIN
char[8]=’r’byte=114u72short=114u72BASIC_LATIN
char[9]=’l’byte=108u6Cshort=108u6CBASIC_LATIN
char[10]=’d’byte=100u64short=100u64BASIC_LATIN
char[11]=’’byte=32u20short=32u20BASIC_LATIN
char[12]=’?’byte=63u3Fshort=63u3FBASIC_LATIN
char[13]=’?’byte=63u3Fshort=63u3FBASIC_LATIN
char[14]=’?’byte=63u3Fshort=63u3FBASIC_LATIN
char[15]=’?’byte=63u3Fshort=63u3FBASIC_LATIN
最惨的就是输出的时候这些’?’真的是问号char(63)了,数据如果是这样就真的没救了
[test2-3]:readhello.utf8.html:decodingasUTF8
string=Helloworld????length=16
char[0]=’H’byte=72u48short=72u48BASIC_LATIN
char[1]=’e’byte=101u65short=101u65BASIC_LATIN
char[2]=’l’byte=108u6Cshort=108u6CBASIC_LATIN
char[3]=’l’byte=108u6Cshort=108u6CBASIC_LATIN
char[4]=’o’byte=111u6Fshort=111u6FBASIC_LATIN转贴于 考试大
[1]
交流JAVA认证考试经验请JAVA认证论坛>>
本文网址: