对此问题的解决办法之一是写一个bean,好处是可重用。 public class ISOtoGBK { public static String convert( String str ) { if (str.trim()=="") { return null; } try { /*Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array.*/ byte[] bytesStr=str.getBytes( "ISO-8859-1" ) ; /*Constructs a new String by decoding the specified array of bytes using the specified charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array. */ return new String( bytesStr, "GBK" ) ; } catch( Exception ex ) { return str ; } } }
|
|