我搜索了帖子后发现
有些人是
String tempStr = "中文";//准备转换的字符
String result = new String(tempStr.getBytes("GB2312"),"UTF-8");//转换后的结果好像这样对码?
我要的中文转UTF-8这样写对吗?

解决方案 »

  1.   

    还有如何知道当前的编码亚 我只知道是中文不知道是GBK还是gb2312 还是iso8859-1
      

  2.   

    String tempStr = "中文";//准备转换的字符
    String result =java.net.URLEncoder.encode(tempStr,"utf-8")
      

  3.   

    String tempStr = "中文";//准备转换的字符
    String tempStr =java.net.URLEncoder.encode(tempStr,"utf-8")
      

  4.   

    1:如何获得当前编码:当前编码默认是系统编码,
    String encoding=System.getProperty("file.encoding"); 
    encoding就是当前编码.2,如何转换成utf-8格式编码:我给你写了个函数,用来转换
      中文字符编码,转换成utf-8格式的:/**
     * inParam:需要转换的gb2312中文字符
     * 返回:该中文字符对应的UTF-8编码的字符
     */
        public static String toUTF(String inPara){
          char temChr;
          int ascChr;
          int i;
          String rtStr=new String("");
          if(inPara==null){
            inPara="";
          }
          for(i=0;i<inPara.length();i++){
            temChr=inPara.charAt(i);
            ascChr=temChr+0;
            rtStr=rtStr+"&#x"+Integer.toHexString(ascChr)+";";
          }
          return rtStr;
        }
      

  5.   

    嘿嘿   chinatelly(atelly)  正解