试试:
    String txt = new String("我是谁?");
    try{
      String rTxt = new String( txt.getBytes( "ISO-8859-1" ), "gb2312" ); //
    }catch(Exception e){}

解决方案 »

  1.   

    没有捕获UnsupportedEncodingException异常
      

  2.   

    捕获异常
    import java.io.*;
    public class Gb {
        public Gb() {
            String rTxt;
            String txt = new String("我是谁?");
            try{
                rTxt = new String(txt.getBytes("ISO-8859-1"),"gb2312");//编码转化
         }catch(Exception e){}
        }    
    }
      

  3.   

    回复人: GamVan(我容易么我) ( ) 信誉:97  2004-11-18 14:22:00  得分: 0  
     
     
       谢谢问题解决,顺便再请教:什么情况下一定要捕获异常阿
      
     
    对于checked exception,是一定得捕获的,如果用IDE的话,会有提示,没有则需要查看javadoc
    对于可能出现的runtime exceptio,如NullPointerException,最好也要catch,以保证系统的健壮性