bytesISO8859 = str1.getBytes("iso-8859-1");
这一句应该改为
bytesISO8859 = str1.getBytes();
因为str1是Unicode编码的,上面你用iso-8859-1参数,表示假设这个String是iso-8859-1编码的
这一句应该改为
bytesISO8859 = str1.getBytes();
因为str1是Unicode编码的,上面你用iso-8859-1参数,表示假设这个String是iso-8859-1编码的
bytesISO8859 = str1.getBytes("iso-8859-1")过的我接收到的参数只是bytesISO8859,请问我怎样才能得到正确的值呢解决后马上给分,在线等待
原因:String str1 = "Hello!你好!";
str1的长度为9,因为是Unicode编码,所以占用18个字节,
bytesISO8859 = str1.getBytes("iso-8859-1")
只获得9个字节,把中文的高字节舍弃了
bytesISO8859 = str1.getBytes();
获得11个字节,因为中文两个字节都是有用的,所以必须多两个字节.想一下:只有这个汉字的地位字节,怎么可能获得这个中文字???
# @(#)font.properties 1.13 02/03/07
#
# Copyright 2002 Sun Microsystems, Inc. All rights reserved.
## Component Font Mappings
#
dialog.0=Arial,ANSI_CHARSET
dialog.1=WingDings,SYMBOL_CHARSET
dialog.2=Symbol,SYMBOL_CHARSETdialog.bold.0=Arial Bold,ANSI_CHARSET
dialog.bold.1=WingDings,SYMBOL_CHARSET
dialog.bold.2=Symbol,SYMBOL_CHARSETdialog.italic.0=Arial Italic,ANSI_CHARSET
dialog.italic.1=WingDings,SYMBOL_CHARSET
dialog.italic.2=Symbol,SYMBOL_CHARSETdialog.bolditalic.0=Arial Bold Italic,ANSI_CHARSET
dialog.bolditalic.1=WingDings,SYMBOL_CHARSET
dialog.bolditalic.2=Symbol,SYMBOL_CHARSETdialoginput.0=Courier New,ANSI_CHARSET
dialoginput.1=WingDings,SYMBOL_CHARSET
dialoginput.2=Symbol,SYMBOL_CHARSETdialoginput.bold.0=Courier New Bold,ANSI_CHARSET
dialoginput.bold.1=WingDings,SYMBOL_CHARSET
dialoginput.bold.2=Symbol,SYMBOL_CHARSETdialoginput.italic.0=Courier New Italic,ANSI_CHARSET
dialoginput.italic.1=WingDings,SYMBOL_CHARSET
dialoginput.italic.2=Symbol,SYMBOL_CHARSETdialoginput.bolditalic.0=Courier New Bold Italic,ANSI_CHARSET
dialoginput.bolditalic.1=WingDings,SYMBOL_CHARSET
dialoginput.bolditalic.2=Symbol,SYMBOL_CHARSETserif.0=Times New Roman,ANSI_CHARSET
serif.1=WingDings,SYMBOL_CHARSET
serif.2=Symbol,SYMBOL_CHARSETserif.bold.0=Times New Roman Bold,ANSI_CHARSET
serif.bold.1=WingDings,SYMBOL_CHARSET
serif.bold.2=Symbol,SYMBOL_CHARSETserif.italic.0=Times New Roman Italic,ANSI_CHARSET
serif.italic.1=WingDings,SYMBOL_CHARSET
serif.italic.2=Symbol,SYMBOL_CHARSETserif.bolditalic.0=Times New Roman Bold Italic,ANSI_CHARSET
serif.bolditalic.1=WingDings,SYMBOL_CHARSET
serif.bolditalic.2=Symbol,SYMBOL_CHARSETsansserif.0=Arial,ANSI_CHARSET
sansserif.1=WingDings,SYMBOL_CHARSET
sansserif.2=Symbol,SYMBOL_CHARSETsansserif.bold.0=Arial Bold,ANSI_CHARSET
sansserif.bold.1=WingDings,SYMBOL_CHARSET
sansserif.bold.2=Symbol,SYMBOL_CHARSETsansserif.italic.0=Arial Italic,ANSI_CHARSET
sansserif.italic.1=WingDings,SYMBOL_CHARSET
sansserif.italic.2=Symbol,SYMBOL_CHARSETsansserif.bolditalic.0=Arial Bold Italic,ANSI_CHARSET
sansserif.bolditalic.1=WingDings,SYMBOL_CHARSET
sansserif.bolditalic.2=Symbol,SYMBOL_CHARSETmonospaced.0=Courier New,ANSI_CHARSET
monospaced.1=WingDings,SYMBOL_CHARSET
monospaced.2=Symbol,SYMBOL_CHARSETmonospaced.bold.0=Courier New Bold,ANSI_CHARSET
monospaced.bold.1=WingDings,SYMBOL_CHARSET
monospaced.bold.2=Symbol,SYMBOL_CHARSETmonospaced.italic.0=Courier New Italic,ANSI_CHARSET
monospaced.italic.1=WingDings,SYMBOL_CHARSET
monospaced.italic.2=Symbol,SYMBOL_CHARSETmonospaced.bolditalic.0=Courier New Bold Italic,ANSI_CHARSET
monospaced.bolditalic.1=WingDings,SYMBOL_CHARSET
monospaced.bolditalic.2=Symbol,SYMBOL_CHARSET# Font File Names
#
filename.Arial=ARIAL.TTF
filename.Arial_Bold=ARIALBD.TTF
filename.Arial_Italic=ARIALI.TTF
filename.Arial_Bold_Italic=ARIALBI.TTFfilename.Courier_New=COUR.TTF
filename.Courier_New_Bold=COURBD.TTF
filename.Courier_New_Italic=COURI.TTF
filename.Courier_New_Bold_Italic=COURBI.TTFfilename.Times_New_Roman=TIMES.TTF
filename.Times_New_Roman_Bold=TIMESBD.TTF
filename.Times_New_Roman_Italic=TIMESI.TTF
filename.Times_New_Roman_Bold_Italic=TIMESBI.TTFfilename.WingDings=WINGDING.TTF
filename.Symbol=SYMBOL.TTF# Missing Glyph Character
#
default.char=2751# Component Font Character Encodings
#
fontcharset.dialog.0=sun.io.CharToByteCp1252
fontcharset.dialog.1=sun.awt.windows.CharToByteWingDings
fontcharset.dialog.2=sun.awt.CharToByteSymbolfontcharset.dialoginput.0=sun.io.CharToByteCp1252
fontcharset.dialoginput.1=sun.awt.windows.CharToByteWingDings
fontcharset.dialoginput.2=sun.awt.CharToByteSymbolfontcharset.serif.0=sun.io.CharToByteCp1252
fontcharset.serif.1=sun.awt.windows.CharToByteWingDings
fontcharset.serif.2=sun.awt.CharToByteSymbolfontcharset.sansserif.0=sun.io.CharToByteCp1252
fontcharset.sansserif.1=sun.awt.windows.CharToByteWingDings
fontcharset.sansserif.2=sun.awt.CharToByteSymbolfontcharset.monospaced.0=sun.io.CharToByteCp1252
fontcharset.monospaced.1=sun.awt.windows.CharToByteWingDings
fontcharset.monospaced.2=sun.awt.CharToByteSymbol# Exclusion Ranges
#
exclusion.dialog.0=0500-20ab,20ad-ffff
exclusion.dialoginput.0=0500-20ab,20ad-ffff
exclusion.serif.0=0500-20ab,20ad-ffff
exclusion.sansserif.0=0500-20ab,20ad-ffff
exclusion.monospaced.0=0500-20ab,20ad-ffff# Text Input Character Set
#
inputtextcharset=ANSI_CHARSET
我觉得也是字节丢失了引起的错误,
bytesISO8859 = str1.getBytes();
在中文操作系统下得到的长度是11位
但在英文平台unix中,默认编码是“ISO-8859-1",得到的只有9位,
那是不是在英文系统下所有的中文都会丢失呢?to: lyndameng(青椒)
我们是在一个大系统里面,不可能修改系统的配置文件,这样会影响其他程序,不过谢谢
只是传输的时候可能会转化成其他的编码
但getBytes()和平台有关,public byte[] getBytes()
Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array. 那我该怎么处理呢?因此就出现上面的结果
那你只有指定GBK了
bytes =str1.getBytes("GBK");
但是操作系统一般都不会用Unicode编码,所以有一个转换过程!
那边传给我的也是系统的默认得值getBytes();
但我怎么转都得不到原有的中文字符了,
上面的例子是我自己写的,模拟unix环境的,我自己用的也是中文Windows,默认就是GBK
getBytes(),应该可以new String(byte[] bytes, String charset)来还原得
怎么我这个例子里就不可以呢?
如果默认不是GBK,你就只好指定了,否则中文就无法恢复呀