import java.io.UnsupportedEncodingException;
public class ziFuChuan{
public static void main(String arg[]){
String hello = "Hello world 世界你好";
try{
hello = new String(hello.getBytes(), "GB2312");
byte[] b=hello.getBytes("gb2312");
System.out.println(b.length);//输出20 hello = new String(hello.getBytes(), "UTF-8");
System.out.println(hello.length());//输出18 byte[] b1=hello.getBytes("UTF-8");
System.out.println(b1.length);//输出28
System.out.println(hello.length());//输出18 }
catch(UnsupportedEncodingException e){}
}
}
public class ziFuChuan{
public static void main(String arg[]){
String hello = "Hello world 世界你好";
try{
hello = new String(hello.getBytes(), "GB2312");
byte[] b=hello.getBytes("gb2312");
System.out.println(b.length);//输出20 hello = new String(hello.getBytes(), "UTF-8");
System.out.println(hello.length());//输出18 byte[] b1=hello.getBytes("UTF-8");
System.out.println(b1.length);//输出28
System.out.println(hello.length());//输出18 }
catch(UnsupportedEncodingException e){}
}
}
解决方案 »
- 一道关于字符串的题
- 在Eclipse中怎么运行程序?
- 怎么才可以找到一个可以实习的公司呢?
- 怎样让Jbutton.setText();的文字不受Jbutton的大小影响啊?
- 连接mysql出现的问题
- 急!!!有一个关于数组传参的程序,请帮助分析结果。。。谢谢!
- 两个字符串数组
- ResultMetaData.getColumnLabel和ResultMetaData.getColumnName为什么都得到Label的值
- @!@请问如何从request中取得上传的图片(关于输入、输出流)@?@
- 自学head first java 35页习题输入后跑不出来 求高手帮看看
- 能采用汉字作为数据库的字段名称吗?
- System.currentTimeMillis()函数相当于WINDOW里哪个函数?我用C++语言的话该调用哪个函数?
import java.io.UnsupportedEncodingException;
public class ZiFuChuan{
public static void main(String arg[]){
String hello = "Hello world 世界你好";
try{
//hello = new String(hello.getBytes(), "GB2312");
byte[] b=hello.getBytes("gb2312");
System.out.println(b.length);//输出20 String hello1 = new String(hello.getBytes(), "gb2312");
System.out.println(hello1.length());//输出16
//hello=new String(hello.getBytes(),"UTF-8");//----(1)
byte[] b1=hello.getBytes("UTF-8");
System.out.println(b1.length);//输出24,如果加上(1)输出28
String hello2=new String(hello.getBytes(),"UTF-8");
System.out.println(hello2.length());//输出18 }
catch(UnsupportedEncodingException e){}
}
}