public class Unicode { public static void main(String[] args) {
String str=new String("试图创建文件");
String s;
try
{
byte[] by = str.getBytes("Unicode");
for(int i=2;i<by.length;i++)
{
s = Integer.toHexString(by[i]);
s = s.length() > 2 ? s.substring(6,8):s;
if(s.length()<2)
{
s = "0"+s;
}
System.out.println(s);
}
}
catch(Exception e)
{
}
}
}
自己改变一下输出的顺序
String str=new String("试图创建文件");
String s;
try
{
byte[] by = str.getBytes("Unicode");
for(int i=2;i<by.length;i++)
{
s = Integer.toHexString(by[i]);
s = s.length() > 2 ? s.substring(6,8):s;
if(s.length()<2)
{
s = "0"+s;
}
System.out.println(s);
}
}
catch(Exception e)
{
}
}
}
自己改变一下输出的顺序
{
public static void main(String[] agrs)
{
String str="我是中国人";
int i;
char chs[] = str.toCharArray();
for(i = 0; i < chs.length; i++)
System.out.println(chs[i] + " = " + (int)chs[i]);
}
}
strVal = new String(strVal.getBytes("GB2312"));
gbk可能也行,但要确定你本机是gb2312的字符集,一般中文的win系统都是。