Chinese.java
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:1k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.tool;
  2. import java.io.*;
  3. //中文字符级转换
  4. public class Chinese {
  5.   public static String toUnicode(String strvalue) {
  6.     try {
  7.       if (strvalue == null) {
  8.         return null;
  9.       }
  10.       else {
  11.         strvalue = new String(strvalue.getBytes("GBK"), "ISO8859_1");
  12.         return strvalue;
  13.       }
  14.     }
  15.     catch (Exception e) {
  16.       return "";
  17.     }
  18.   }
  19.   public static String toChinese(String strvalue) {
  20.     try {
  21.       if (strvalue == null) {
  22.         return "";
  23.       }
  24.       else {
  25.         strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK");
  26.         return strvalue;
  27.       }
  28.     }
  29.     catch (Exception e) {
  30.       return "";
  31.     }
  32.   }
  33.   public static String chinese(String a) {
  34.     try {
  35.       return new String(a.getBytes("ISO-8859-1"));
  36.     }
  37.     catch (UnsupportedEncodingException ex) {
  38.       return null;
  39.     }
  40.   }
  41. }