Convert character encoding to GBK code

From , 4 Years ago, written in Java, viewed 55 times.
URL https://pastebin.vip/view/766ebcd5
  1.         /** 中文超大字符集 */
  2.         public static final String GBK = "GBK";
  3.  
  4.         /**
  5.          * 将字符编码转换成GBK码
  6.          */
  7.         public String toGBK(String str) throws UnsupportedEncodingException {
  8.                 return this.changeCharset(str, GBK);
  9.         }
  10.  
  11.  
  12.         /**
  13.          * 字符串编码转换的实现方法
  14.          *
  15.          * @param str
  16.          *            待转换编码的字符串
  17.          * @param newCharset
  18.          *            目标编码
  19.          * @return
  20.          * @throws UnsupportedEncodingException
  21.          */
  22.         public String changeCharset(String str, String newCharset)
  23.                         throws UnsupportedEncodingException {
  24.                 if (str != null) {
  25.                         // 用默认字符编码解码字符串。
  26.                         byte[] bs = str.getBytes();
  27.                         // 用新的字符编码生成字符串
  28.                         return new String(bs, newCharset);
  29.                 }
  30.                 return null;
  31.         }

Reply to "Convert character encoding to GBK code"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website