1. 程式人生 > >java中url中文轉碼問題

java中url中文轉碼問題

public static void main(String[] args){
try {
    
           System.out.println("中文");//1


           System.out.println("中文".getBytes());//2


           System.out.println("中文".getBytes("GB2312"));//3


           System.out.println("中文".getBytes("ISO8859_1"));//4
           


           System.out.println(new String("中文".getBytes()));//5


           System.out.println(new String("中文".getBytes(),"GB2312"));//6


           System.out.println(new String("中文".getBytes(),"ISO8859_1"));//7


           System.out.println(new String("中文".getBytes("GB2312")));//8


           System.out.println(new String("中文".getBytes("GB2312"),"GB2312"));//9
           


           System.out.println(new String("中文".getBytes("GB2312"),"ISO8859_1"));//10


           System.out.println(new String("中文".getBytes("ISO8859_1")));//11


           System.out.println(new String("中文".getBytes("ISO8859_1"),"utf-8"));//12


           System.out.println(new String("中文傳送簡訊".getBytes("ISO8859_1"),"utf-8"));//13
           
           //編碼與解碼
           String cont=URLEncoder.encode(new String("你在幹什麼啊  33335"), "utf-8");
           System.out.println("0:"+cont);           
           String after=URLDecoder.decode(cont, "utf-8");
           System.out.println("1:"+after);
           
      } catch (Exception e) {
    System.out.println(e.getMessage());
    }
}